Skip to content

Commit

Permalink
Properly fixing NVCC builds
Browse files Browse the repository at this point in the history
Some code in the binpacking distribution policy produced ICEs in the nvcc
frontend. This code has been put into a different TU such that it doesn't
need to be processed by nvcc.
  • Loading branch information
sithhell committed Sep 5, 2017
1 parent 56a0a30 commit 75c9475
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 115 deletions.
124 changes: 9 additions & 115 deletions hpx/runtime/components/binpacking_distribution_policy.hpp
Expand Up @@ -8,8 +8,6 @@
#if !defined(HPX_COMPONENTS_BINPACKING_DISTRIBUTION_POLICY_APR_10_2015_0344PM)
#define HPX_COMPONENTS_BINPACKING_DISTRIBUTION_POLICY_APR_10_2015_0344PM

#if !defined(HPX_COMPUTE_DEVICE_CODE)

#include <hpx/config.hpp>
#include <hpx/dataflow.hpp>
#include <hpx/lcos/future.hpp>
Expand Down Expand Up @@ -41,122 +39,20 @@ namespace hpx { namespace components
namespace detail
{
/// \cond NOINTERNAL
inline std::vector<std::size_t>
get_items_count(std::size_t count, std::vector<std::uint64_t> const& values)
{
std::size_t maxcount = 0;
std::size_t existing = 0;

for (std::uint64_t value: values)
{
maxcount = (std::max)(maxcount, std::size_t(value));
existing += std::size_t(value);
}

// distribute the number of components to create in a way, so that
// the overall number of component instances on all localities is
// approximately the same
std::size_t num_localities = values.size();

// calculate the number of new instances to create on each of the
// localities
std::vector<std::size_t> to_create(num_localities, 0);

bool even_fill = true;
while (even_fill)
{
even_fill = false;
for (std::size_t i = 0; i != num_localities; ++i)
{
if(values[i] + to_create[i] >= maxcount) continue;
even_fill = true;

++to_create[i];
--count;
if (count == 0) break;
}
}
std::size_t i = 0;
while (count != 0)
{
++to_create[i];
i = (i + 1) % num_localities;
--count;
}

return to_create;
}
HPX_EXPORT std::vector<std::size_t>
get_items_count(std::size_t count, std::vector<std::uint64_t> const& values);

inline hpx::future<std::vector<std::uint64_t> >
HPX_EXPORT hpx::future<std::vector<std::uint64_t> >
retrieve_counter_values(
std::vector<performance_counters::performance_counter> && counters)
{
using namespace hpx::performance_counters;

std::vector<hpx::future<std::uint64_t> > values;
values.reserve(counters.size());

for (performance_counter const& counter: counters)
values.push_back(counter.get_value<std::uint64_t>());

return hpx::dataflow(hpx::launch::sync,
hpx::util::unwrapping(
[](std::vector<std::uint64_t> && values)
{
return values;
}),
std::move(values));
}

template <typename String>
hpx::future<std::vector<std::uint64_t> > get_counter_values(
String component_name, std::string const& counter_name,
std::vector<hpx::id_type> const& localities)
{
using namespace hpx::performance_counters;

// create performance counters on all localities
std::vector<performance_counter> counters;
counters.reserve(localities.size());

if (counter_name[counter_name.size()-1] == '@')
{
std::string name(counter_name + component_name);
std::vector<performance_counters::performance_counter> && counters);

for (hpx::id_type const& id: localities)
counters.push_back(performance_counter(name, id));
}
else
{
for (hpx::id_type const& id: localities)
counters.push_back(performance_counter(counter_name, id));
}

return hpx::dataflow(
&retrieve_counter_values, std::move(counters));
}
HPX_EXPORT hpx::future<std::vector<std::uint64_t> > get_counter_values(
std::string component_name, std::string const& counter_name,
std::vector<hpx::id_type> const& localities);

inline hpx::id_type const& get_best_locality(
HPX_EXPORT hpx::id_type const& get_best_locality(
hpx::future<std::vector<std::uint64_t> > && f,
std::vector<hpx::id_type> const& localities)
{
std::vector<std::uint64_t> values = f.get();

std::size_t best_locality = 0;
std::uint64_t min_value =
(std::numeric_limits<std::uint64_t>::max)();

for (std::size_t i = 0; i != values.size(); ++i)
{
if (min_value > values[i])
{
min_value = values[i];
best_locality = i;
}
}

return localities[best_locality];
}
std::vector<hpx::id_type> const& localities);

template <typename Component>
struct create_helper
Expand Down Expand Up @@ -488,5 +384,3 @@ namespace hpx
/// \endcond

#endif

#endif
128 changes: 128 additions & 0 deletions src/components/binpacking_distribution_policy.cpp
@@ -0,0 +1,128 @@
// Copyright (c) 2007-2016 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/runtime/components/binpacking_distribution_policy.hpp>

namespace hpx { namespace components
{
namespace detail
{
std::vector<std::size_t>
get_items_count(std::size_t count, std::vector<std::uint64_t> const& values)
{
std::size_t maxcount = 0;
std::size_t existing = 0;

for (std::uint64_t value: values)
{
maxcount = (std::max)(maxcount, std::size_t(value));
existing += std::size_t(value);
}

// distribute the number of components to create in a way, so that
// the overall number of component instances on all localities is
// approximately the same
std::size_t num_localities = values.size();

// calculate the number of new instances to create on each of the
// localities
std::vector<std::size_t> to_create(num_localities, 0);

bool even_fill = true;
while (even_fill)
{
even_fill = false;
for (std::size_t i = 0; i != num_localities; ++i)
{
if(values[i] + to_create[i] >= maxcount) continue;
even_fill = true;

++to_create[i];
--count;
if (count == 0) break;
}
}
std::size_t i = 0;
while (count != 0)
{
++to_create[i];
i = (i + 1) % num_localities;
--count;
}

return to_create;
}

hpx::future<std::vector<std::uint64_t> >
retrieve_counter_values(
std::vector<performance_counters::performance_counter> && counters)
{
using namespace hpx::performance_counters;

std::vector<hpx::future<std::uint64_t> > values;
values.reserve(counters.size());

for (performance_counter const& counter: counters)
values.push_back(counter.get_value<std::uint64_t>());

return hpx::dataflow(hpx::launch::sync,
hpx::util::unwrapping(
[](std::vector<std::uint64_t> && values)
{
return values;
}),
std::move(values));
}

hpx::future<std::vector<std::uint64_t> > get_counter_values(
std::string component_name, std::string const& counter_name,
std::vector<hpx::id_type> const& localities)
{
using namespace hpx::performance_counters;

// create performance counters on all localities
std::vector<performance_counter> counters;
counters.reserve(localities.size());

if (counter_name[counter_name.size()-1] == '@')
{
std::string name(counter_name + component_name);

for (hpx::id_type const& id: localities)
counters.push_back(performance_counter(name, id));
}
else
{
for (hpx::id_type const& id: localities)
counters.push_back(performance_counter(counter_name, id));
}

return hpx::dataflow(
&retrieve_counter_values, std::move(counters));
}

hpx::id_type const& get_best_locality(
hpx::future<std::vector<std::uint64_t> > && f,
std::vector<hpx::id_type> const& localities)
{
std::vector<std::uint64_t> values = f.get();

std::size_t best_locality = 0;
std::uint64_t min_value =
(std::numeric_limits<std::uint64_t>::max)();

for (std::size_t i = 0; i != values.size(); ++i)
{
if (min_value > values[i])
{
min_value = values[i];
best_locality = i;
}
}

return localities[best_locality];
}
}
}}

0 comments on commit 75c9475

Please sign in to comment.