Skip to content

Commit

Permalink
Adding steal-half functionalities to work-requesting scheduler
Browse files Browse the repository at this point in the history
- adding new scheduler: --hpx:queuing=local-workrequesting-mc that relies on the Moody-Camel queue
- flyby: a lot of cleanup in various related places
- flyby: fixing config-registry for command line module
  • Loading branch information
hkaiser committed Jan 20, 2024
1 parent c0d79c8 commit 32650b0
Show file tree
Hide file tree
Showing 40 changed files with 1,014 additions and 780 deletions.
4 changes: 3 additions & 1 deletion cmake/HPX_PrintSummary.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2017-2022 Hartmut Kaiser
# Copyright (c) 2017-2024 Hartmut Kaiser
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -70,6 +70,8 @@ function(create_configuration_summary message module_name)
PROPERTY VALUE
)
hpx_info(" ${_variableName}=${_value}")
else()
hpx_info(" value not found for ${_variableName}")
endif()

string(REPLACE "_WITH_" "_HAVE_" __variableName ${_variableName})
Expand Down
2 changes: 1 addition & 1 deletion cmake/templates/HPXConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ endif()
# NLohnmann JSON can be installed by HPX or externally installed. In the first
# case we use exported targets, in the second we find JSON again using
# find_package.
if(HPX_COMMAND_LINE_HANDLING_WITH_JSON_CONFIGURATION_FILES)
if(HPX_COMMAND_LINE_HANDLING_LOCAL_WITH_JSON_CONFIGURATION_FILES)
if(HPX_WITH_FETCH_JSON)
include("${CMAKE_CURRENT_LIST_DIR}/HPXJsonTarget.cmake")
else()
Expand Down
5 changes: 3 additions & 2 deletions docs/sphinx/manual/hpx_runtime_and_resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ policy use the command line option
Work requesting scheduling policies
-----------------------------------

* invoke using: :option:`--hpx:queuing`\ ``local-workrequesting-fifo``
or using :option:`--hpx:queuing`\ ``local-workrequesting-lifo``
* invoke using: :option:`--hpx:queuing`\ ``local-workrequesting-fifo``,
using :option:`--hpx:queuing`\ ``local-workrequesting-lifo``,
or using :option:`--hpx:queuing`\ ``local-workrequesting-mc``

The work-requesting policies rely on a different mechanism of balancing work
between cores (compared to the other policies listed above). Instead of actively
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1573,15 +1573,15 @@ The predefined command line options for any application using
``local-priority-fifo``, ``local-priority-lifo``, ``static``,
``static-priority``, ``abp-priority-fifo``,
``local-workrequesting-fifo``, ``local-workrequesting-lifo``
and ``abp-priority-lifo``
``local-workrequesting-mc``, and ``abp-priority-lifo``
(default: ``local-priority-fifo``).

.. option:: --hpx:high-priority-threads arg

The number of operating system threads maintaining a high priority queue
(default: number of OS threads), valid for :option:`--hpx:queuing`\
``=abp-priority``, :option:`--hpx:queuing`\ ``=static-priority`` and
:option:`--hpx:queuing`\ ``=local-priority`` only.
``=abp-priority``, :option:`--hpx:queuing`\ ``static-priority`` and
:option:`--hpx:queuing`\ ``local-priority`` only.

.. option:: --hpx:numa-sensitive

Expand Down
1 change: 1 addition & 0 deletions libs/core/affinity/src/affinity_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace hpx::threads::policies::detail {
, pu_step_(1)
, used_cores_(0)
, affinity_domain_("pu")
, no_affinity_()
, use_process_mask_(false)
, num_pus_needed_(0)
{
Expand Down
20 changes: 14 additions & 6 deletions libs/core/command_line_handling_local/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2023 The STE||AR-Group
# Copyright (c) 2019-2024 The STE||AR-Group
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -9,17 +9,25 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# Enable reading JSON formatted configuration files on the command line
set(HPX_COMMAND_LINE_HANDLING_WITH_JSON_CONFIGURATION_FILES_DEFAULT OFF)
if(HPX_COMMAND_LINE_HANDLING_WITH_JSON_CONFIGURATION_FILES)
set(HPX_COMMAND_LINE_HANDLING_WITH_JSON_CONFIGURATION_FILES_DEFAULT
${HPX_COMMAND_LINE_HANDLING_WITH_JSON_CONFIGURATION_FILES}
)
endif()

hpx_option(
HPX_COMMAND_LINE_HANDLING_WITH_JSON_CONFIGURATION_FILES
HPX_COMMAND_LINE_HANDLING_LOCAL_WITH_JSON_CONFIGURATION_FILES
BOOL
"Enable reading JSON formatted configuration files on the command line. (default: OFF)"
OFF
"Enable reading JSON formatted configuration files on the command line.\n
(default: ${HPX_COMMAND_LINE_HANDLING_WITH_JSON_CONFIGURATION_FILES_DEFAULT})"
${HPX_COMMAND_LINE_HANDLING_WITH_JSON_CONFIGURATION_FILES_DEFAULT}
ADVANCED
CATEGORY "Modules"
MODULE COMMAND_LINE_HANDLING_LOCAL
)

if(HPX_COMMAND_LINE_HANDLING_WITH_JSON_CONFIGURATION_FILES)
if(HPX_COMMAND_LINE_HANDLING_LOCAL_WITH_JSON_CONFIGURATION_FILES)
hpx_add_config_define_namespace(
DEFINE HPX_COMMAND_LINE_HANDLING_HAVE_JSON_CONFIGURATION_FILES
NAMESPACE COMMAND_LINE_HANDLING_LOCAL
Expand All @@ -37,7 +45,7 @@ set(command_line_handling_local_sources
parse_command_line_local.cpp
)

if(HPX_COMMAND_LINE_HANDLING_WITH_JSON_CONFIGURATION_FILES)
if(HPX_COMMAND_LINE_HANDLING_LOCAL_WITH_JSON_CONFIGURATION_FILES)
include(HPX_SetupJSON)
set(command_line_handling_local_dependencies Json::json)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,16 @@ namespace hpx::local::detail {
"larger than number of threads (--hpx:threads)");
}

if (!(queuing_ == "local-priority" || queuing_ == "abp-priority"))
if (!(queuing_ == "local-priority" || queuing_ == "abp-priority" ||
queuing_.find("local-workrequesting") != 0))
{
throw hpx::detail::command_line_error(
"Invalid command line option --hpx:high-priority-threads, "
"valid for --hpx:queuing=local-priority and "
"--hpx:queuing=abp-priority only");
"valid for --hpx:queuing=local-priority, "
"--hpx:queuing=local-workrequesting-fifo, "
"--hpx:queuing=local-workrequesting-lifo, "
"--hpx:queuing=local-workrequesting-mc, "
"and --hpx:queuing=abp-priority only");
}

ini_config.emplace_back("hpx.thread_queue.high_priority_queues!=" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ namespace hpx::local::detail {
"--hpx:queuing=static, --hpx:queuing=static-priority, "
"--hpx:queuing=local-workrequesting-fifo, "
"--hpx:queuing=local-workrequesting-lifo, "
"--hpx:queuing=local-workrequesting-mc, "
"and --hpx:queuing=local-priority only")
("hpx:pu-step", value<std::size_t>(),
"the step between used processing unit numbers for this "
Expand All @@ -488,6 +489,7 @@ namespace hpx::local::detail {
"--hpx:queuing=static, --hpx:queuing=static-priority "
"--hpx:queuing=local-workrequesting-fifo, "
"--hpx:queuing=local-workrequesting-lifo, "
"--hpx:queuing=local-workrequesting-mc, "
"and --hpx:queuing=local-priority only")
("hpx:affinity", value<std::string>(),
"the affinity domain the OS threads will be confined to, "
Expand All @@ -496,6 +498,7 @@ namespace hpx::local::detail {
"--hpx:queuing=static, --hpx:queuing=static-priority "
"--hpx:queuing=local-workrequesting-fifo, "
"--hpx:queuing=local-workrequesting-lifo, "
"--hpx:queuing=local-workrequesting-mc, "
" and --hpx:queuing=local-priority only")
("hpx:bind", value<std::vector<std::string> >()->composing(),
"the detailed affinity description for the OS threads, see "
Expand All @@ -515,21 +518,23 @@ namespace hpx::local::detail {
"each processing unit")
("hpx:cores", value<std::string>(),
"the number of cores to utilize for this HPX "
"locality (default: 'all', i.e. the number of cores is based on "
"the number of total cores in the system)")
"locality (default: 'all', i.e. the number of cores is based "
"on the number of total cores in the system)")
("hpx:queuing", value<std::string>(),
"the queue scheduling policy to use, options are "
"'local', 'local-priority-fifo','local-priority-lifo', "
"'abp-priority-fifo', 'abp-priority-lifo', 'static', "
"'static-priority', 'local-workrequesting-fifo', and "
"'local-workrequesting-lifo' (default: 'local-priority'; "
"all option values can be abbreviated)")
"'static-priority', 'local-workrequesting-fifo',"
"'local-workrequesting-lifo', and 'local-workrequesting-mc' "
"(default: 'local-priority'; all option values can be "
"abbreviated)")
("hpx:high-priority-threads", value<std::size_t>(),
"the number of operating system threads maintaining a high "
"priority queue (default: number of OS threads), valid for "
"--hpx:queuing=local-priority,--hpx:queuing=static-priority, "
"--hpx:queuing=local-workrequesting-fifo, "
"--hpx:queuing=local-workrequesting-lifo, "
"--hpx:queuing=local-workrequesting-mc, "
" and --hpx:queuing=abp-priority only)")
("hpx:numa-sensitive", value<std::size_t>()->implicit_value(0),
"makes the local-priority scheduler NUMA sensitive ("
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023 The STE||AR-Group
# Copyright (c) 2020-2024 The STE||AR-Group
# 2011 Bryce Adelstein-Lelbach
#
# SPDX-License-Identifier: BSL-1.0
Expand All @@ -7,7 +7,7 @@

set(tests)

if(HPX_COMMAND_LINE_HANDLING_WITH_JSON_CONFIGURATION_FILES)
if(HPX_COMMAND_LINE_HANDLING_LOCAL_WITH_JSON_CONFIGURATION_FILES)
set(tests json_config_file)

set(json_config_file_PARAMETERS
Expand Down
32 changes: 16 additions & 16 deletions libs/core/concurrency/include/hpx/concurrency/concurrentqueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@
#include <thread> // partly for __WINPTHREADS_VERSION if on MinGW-w64 w/ POSIX threading

// Platform-specific definitions of a numeric thread ID type and an invalid value
namespace hpx { namespace concurrency { namespace details {
namespace hpx::concurrency::details {
template<typename thread_id_t> struct thread_id_converter {
typedef thread_id_t thread_id_numeric_size_t;
typedef thread_id_t thread_id_hash_t;
static thread_id_hash_t prehash(thread_id_t const& x) { return x; }
};
} } }
}
#if defined(MCDBGQ_USE_RELACY)
namespace hpx { namespace concurrency { namespace details {
typedef std::uint32_t thread_id_t;
Expand All @@ -109,15 +109,15 @@ namespace hpx { namespace concurrency { namespace details {
// No sense pulling in windows.h in a header, we'll manually declare the function
// we use and rely on backwards-compatibility for this not to break
extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId(void);
namespace hpx { namespace concurrency { namespace details {
namespace hpx::concurrency::details {
static_assert(sizeof(unsigned long) == sizeof(std::uint32_t), "Expected size of unsigned long to be 32 bits on Windows");
typedef std::uint32_t thread_id_t;
static const thread_id_t invalid_thread_id = 0; // See http://blogs.msdn.com/b/oldnewthing/archive/2004/02/23/78395.aspx
static const thread_id_t invalid_thread_id2 = 0xFFFFFFFFU; // Not technically guaranteed to be invalid, but is never used in practice. Note that all Win32 thread IDs are presently multiples of 4.
static constexpr thread_id_t invalid_thread_id = 0; // See http://blogs.msdn.com/b/oldnewthing/archive/2004/02/23/78395.aspx
static constexpr thread_id_t invalid_thread_id2 = 0xFFFFFFFFU; // Not technically guaranteed to be invalid, but is never used in practice. Note that all Win32 thread IDs are presently multiples of 4.
static inline thread_id_t thread_id() { return static_cast<thread_id_t>(::GetCurrentThreadId()); }
} } }
}
#elif defined(__arm__) || defined(_M_ARM) || defined(__aarch64__) || (defined(__APPLE__) && TARGET_OS_IPHONE)
namespace hpx { namespace concurrency { namespace details {
namespace hpx::concurrency::details {
static_assert(sizeof(std::thread::id) == 4 || sizeof(std::thread::id) == 8, "std::thread::id is expected to be either 4 or 8 bytes");

typedef std::thread::id thread_id_t;
Expand Down Expand Up @@ -149,7 +149,7 @@ namespace hpx { namespace concurrency { namespace details {
#endif
}
};
} } }
}
#else
// Use a nice trick from this answer: http://stackoverflow.com/a/8438730/21475
// In order to get a numeric thread ID in a platform-independent way, we use a thread-local
Expand All @@ -162,12 +162,12 @@ namespace hpx { namespace concurrency { namespace details {
// Assume C++11 compliant compiler
#define MOODYCAMEL_THREADLOCAL thread_local
#endif
namespace hpx { namespace concurrency { namespace details {
namespace hpx::concurrency::details {
typedef std::uintptr_t thread_id_t;
static const thread_id_t invalid_thread_id = 0; // Address can't be nullptr
static const thread_id_t invalid_thread_id2 = 1; // Member accesses off a null pointer are also generally invalid. Plus it's not aligned.
static constexpr thread_id_t invalid_thread_id = 0; // Address can't be nullptr
static constexpr thread_id_t invalid_thread_id2 = 1; // Member accesses off a null pointer are also generally invalid. Plus it's not aligned.
static inline thread_id_t thread_id() { static MOODYCAMEL_THREADLOCAL int x; return reinterpret_cast<thread_id_t>(&x); }
} } }
}
#endif

// Exceptions
Expand Down Expand Up @@ -235,21 +235,21 @@ namespace hpx { namespace concurrency { namespace details {
#endif

// Compiler-specific likely/unlikely hints
namespace hpx { namespace concurrency { namespace details {
namespace hpx::concurrency::details {
#if defined(__GNUC__)
static inline bool (likely)(bool x) { return __builtin_expect((x), true); }
static inline bool (unlikely)(bool x) { return __builtin_expect((x), false); }
#else
static inline bool (likely)(bool x) { return x; }
static inline bool (unlikely)(bool x) { return x; }
#endif
} } }
}

#ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG
#include "internal/concurrentqueue_internal_debug.h"
#endif

namespace hpx { namespace concurrency {
namespace hpx::concurrency {
namespace details {
template<typename T>
struct const_numeric_max {
Expand Down Expand Up @@ -3650,7 +3650,7 @@ inline void swap(typename ConcurrentQueue<T, Traits>::ImplicitProducerKVP& a, ty
a.swap(b);
}

} }
}

#if defined(__GNUC__)
#pragma GCC diagnostic pop
Expand Down
2 changes: 2 additions & 0 deletions libs/core/config/include/hpx/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,6 @@
# define HPX_HAVE_MAX_CPU_COUNT 256
#endif

#define HPX_HAVE_MAX_CPU_COUNT 64

// clang-format on
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2017 Shoshana Jakobovits
// Copyright (c) 2017-2022 Hartmut Kaiser
// Copyright (c) 2017-2024 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -50,7 +50,7 @@ namespace hpx::resource::detail {
// counter ... overall, in all the thread pools
static std::size_t num_threads_overall;

init_pool_data(std::string const& name, scheduling_policy policy,
init_pool_data(std::string const& name, scheduling_policy sched,
hpx::threads::policies::scheduler_mode mode,
background_work_function func = background_work_function());

Expand All @@ -75,7 +75,7 @@ namespace hpx::resource::detail {
hpx::threads::policies::scheduler_mode mode_;
scheduler_function create_function_;

// possible additional beckground work to run on this scheduler
// possible additional background work to run on this scheduler
background_work_function background_work_;
};

Expand All @@ -86,6 +86,12 @@ namespace hpx::resource::detail {

public:
partitioner();

partitioner(partitioner const&) = delete;
partitioner(partitioner&&) = delete;
partitioner& operator=(partitioner const&) = delete;
partitioner& operator=(partitioner&&) = delete;

~partitioner();

void print_init_pool_data(std::ostream&) const;
Expand Down Expand Up @@ -203,7 +209,7 @@ namespace hpx::resource::detail {
private:
////////////////////////////////////////////////////////////////////////
void fill_topology_vectors();
bool pu_exposed(std::size_t pid);
bool pu_exposed(std::size_t pu_num) const;

////////////////////////////////////////////////////////////////////////
// called in hpx_init run_or_start
Expand Down Expand Up @@ -232,7 +238,7 @@ namespace hpx::resource::detail {
// counter for instance numbers
static std::atomic<int> instance_number_counter_;

// holds all of the command line switches
// holds all the command line switches
util::section rtcfg_;
std::size_t first_core_;
std::size_t pus_needed_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ namespace hpx::resource {
shared_priority = 7,
local_workrequesting_fifo = 8,
local_workrequesting_lifo = 9,
local_workrequesting_mc = 10,
};

#define HPX_SCHEDULING_POLICY_UNSCOPED_ENUM_DEPRECATION_MSG \
Expand Down
Loading

0 comments on commit 32650b0

Please sign in to comment.