1 /////////////////////////////////////////////////////////////////////////////// 2 // Copyright (c) 2016 Thomas Heller 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 /////////////////////////////////////////////////////////////////////////////// 7 8 #ifndef HPX_COMPUTE_HOST_TARGET_HPP 9 #define HPX_COMPUTE_HOST_TARGET_HPP 10 11 #include <hpx/config.hpp> 12 13 #include <hpx/compute/host/get_targets.hpp> 14 #include <hpx/lcos/future.hpp> 15 #include <hpx/runtime/find_here.hpp> 16 #include <hpx/runtime/serialization/serialization_fwd.hpp> 17 #include <hpx/runtime/threads/topology.hpp> 18 19 #include <cstddef> 20 #include <utility> 21 #include <vector> 22 23 #include <hpx/config/warnings_prefix.hpp> 24 25 namespace hpx { namespace compute { namespace host 26 { 27 struct target 28 { 29 public: 30 struct HPX_EXPORT native_handle_type 31 { native_handle_typehpx::compute::host::target::native_handle_type32 native_handle_type() 33 : mask_(hpx::threads::get_topology().get_machine_affinity_mask()) 34 {} 35 native_handle_typehpx::compute::host::target::native_handle_type36 explicit native_handle_type(hpx::threads::mask_type mask) 37 : mask_(mask) 38 {} 39 get_devicehpx::compute::host::target::native_handle_type40 hpx::threads::mask_type& get_device() noexcept 41 { 42 return mask_; 43 } get_devicehpx::compute::host::target::native_handle_type44 hpx::threads::mask_type const& get_device() const noexcept 45 { 46 return mask_; 47 } 48 49 private: 50 friend struct target; 51 52 hpx::threads::mask_type mask_; 53 }; 54 55 public: 56 // Constructs default target targethpx::compute::host::target57 target() 58 : handle_(), locality_(hpx::find_here()) 59 { 60 } 61 62 // Constructs target from a given mask of processing units targethpx::compute::host::target63 explicit target(hpx::threads::mask_type mask) 64 : handle_(mask), locality_(hpx::find_here()) 65 { 66 } 67 targethpx::compute::host::target68 explicit target(hpx::id_type const& locality) 69 : handle_(), locality_(locality) 70 { 71 } 72 targethpx::compute::host::target73 target(hpx::id_type const& locality, hpx::threads::mask_type mask) 74 : handle_(mask), locality_(locality) 75 { 76 } 77 native_handlehpx::compute::host::target78 native_handle_type & native_handle() noexcept 79 { 80 return handle_; 81 } native_handlehpx::compute::host::target82 native_handle_type const& native_handle() const noexcept 83 { 84 return handle_; 85 } 86 get_localityhpx::compute::host::target87 hpx::id_type const& get_locality() const noexcept 88 { 89 return locality_; 90 } 91 92 std::pair<std::size_t, std::size_t> num_pus() const; 93 synchronizehpx::compute::host::target94 void synchronize() const 95 { 96 // nothing to do here... 97 } 98 get_futurehpx::compute::host::target99 hpx::future<void> get_future() const 100 { 101 return hpx::make_ready_future(); 102 } 103 get_local_targetshpx::compute::host::target104 static std::vector<target> get_local_targets() 105 { 106 return host::get_local_targets(); 107 } 108 static hpx::future<std::vector<target> > get_targetshpx::compute::host::target109 get_targets(hpx::id_type const& locality) 110 { 111 return host::get_targets(locality); 112 } 113 operator ==(target const & lhs,target const & rhs)114 friend bool operator==(target const& lhs, target const& rhs) 115 { 116 return lhs.handle_.get_device() == rhs.handle_.get_device() && 117 lhs.locality_ == rhs.locality_; 118 } 119 120 private: 121 friend class hpx::serialization::access; 122 123 void serialize(serialization::input_archive& ar, const unsigned int); 124 void serialize(serialization::output_archive& ar, const unsigned int); 125 126 native_handle_type handle_; 127 hpx::id_type locality_; 128 }; 129 }}} 130 131 #include <hpx/config/warnings_suffix.hpp> 132 133 #endif 134