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 #include <hpx/compute/host/target.hpp> 9 #include <hpx/runtime.hpp> 10 #include <hpx/runtime/get_os_thread_count.hpp> 11 #include <hpx/runtime/resource/detail/partitioner.hpp> 12 #include <hpx/runtime/serialization/serialize.hpp> 13 #include <hpx/runtime/threads/threadmanager.hpp> 14 #include <hpx/runtime/threads/topology.hpp> 15 16 #if defined(HPX_HAVE_MORE_THAN_64_THREADS) 17 # if defined(HPX_HAVE_MAX_CPU_COUNT) 18 # include <hpx/runtime/serialization/bitset.hpp> 19 # else 20 # include <hpx/runtime/serialization/dynamic_bitset.hpp> 21 # endif 22 #endif 23 24 #include <cstddef> 25 #include <utility> 26 27 namespace hpx { namespace compute { namespace host 28 { num_pus() const29 std::pair<std::size_t, std::size_t> target::num_pus() const 30 { 31 auto& rp = hpx::resource::get_partitioner(); 32 std::size_t num_os_threads = hpx::get_os_thread_count(); 33 34 hpx::threads::mask_type mask = native_handle().get_device(); 35 std::size_t mask_size = hpx::threads::mask_size(mask); 36 37 std::size_t num_thread = 0; 38 for (/**/; num_thread != num_os_threads; ++num_thread) 39 { 40 if (hpx::threads::bit_and( 41 mask, rp.get_pu_mask(num_thread), mask_size)) 42 { 43 break; 44 } 45 } 46 return std::make_pair(num_thread, hpx::threads::count(mask)); 47 } 48 serialize(serialization::input_archive & ar,const unsigned int)49 void target::serialize(serialization::input_archive& ar, const unsigned int) 50 { 51 ar >> handle_.mask_ >> locality_; 52 } 53 serialize(serialization::output_archive & ar,const unsigned int)54 void target::serialize(serialization::output_archive& ar, const unsigned int) 55 { 56 ar << handle_.mask_ << locality_; 57 } 58 }}} 59