Introduce opencl_work_func_t to make code more readable (#4446)
This commit is contained in:
parent
2903a9977a
commit
2526b75e61
6 changed files with 38 additions and 18 deletions
|
@ -23,7 +23,7 @@ std::string nano::to_string (nano::work_version const version_a)
|
|||
return result;
|
||||
}
|
||||
|
||||
nano::work_pool::work_pool (nano::network_constants & network_constants, unsigned max_threads_a, std::chrono::nanoseconds pow_rate_limiter_a, std::function<boost::optional<uint64_t> (nano::work_version const, nano::root const &, uint64_t, std::atomic<int> &)> opencl_a) :
|
||||
nano::work_pool::work_pool (nano::network_constants & network_constants, unsigned max_threads_a, std::chrono::nanoseconds pow_rate_limiter_a, nano::opencl_work_func_t opencl_a) :
|
||||
network_constants{ network_constants },
|
||||
ticket (0),
|
||||
done (false),
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <nano/lib/numbers.hpp>
|
||||
#include <nano/lib/observer_set.hpp>
|
||||
#include <nano/lib/utility.hpp>
|
||||
#include <nano/node/openclwork.hpp>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
|
@ -16,6 +17,9 @@ namespace nano
|
|||
{
|
||||
std::string to_string (nano::work_version const version_a);
|
||||
|
||||
// type of function that does the work generation with an optional return value
|
||||
using opencl_work_func_t = std::function<boost::optional<uint64_t> (nano::work_version const, nano::root const &, uint64_t, std::atomic<int> &)>;
|
||||
|
||||
class block;
|
||||
class block_details;
|
||||
enum class block_type : uint8_t;
|
||||
|
@ -36,7 +40,7 @@ public:
|
|||
class work_pool final
|
||||
{
|
||||
public:
|
||||
work_pool (nano::network_constants & network_constants, unsigned, std::chrono::nanoseconds = std::chrono::nanoseconds (0), std::function<boost::optional<uint64_t> (nano::work_version const, nano::root const &, uint64_t, std::atomic<int> &)> = nullptr);
|
||||
work_pool (nano::network_constants & network_constants, unsigned, std::chrono::nanoseconds = std::chrono::nanoseconds (0), nano::opencl_work_func_t = nullptr);
|
||||
~work_pool ();
|
||||
void loop (uint64_t);
|
||||
void stop ();
|
||||
|
@ -55,7 +59,7 @@ public:
|
|||
nano::mutex mutex{ mutex_identifier (mutexes::work_pool) };
|
||||
nano::condition_variable producer_condition;
|
||||
std::chrono::nanoseconds pow_rate_limiter;
|
||||
std::function<boost::optional<uint64_t> (nano::work_version const, nano::root const &, uint64_t, std::atomic<int> &)> opencl;
|
||||
nano::opencl_work_func_t opencl;
|
||||
nano::observer_set<bool> work_observers;
|
||||
};
|
||||
|
||||
|
|
|
@ -99,11 +99,15 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag
|
|||
}
|
||||
|
||||
boost::asio::io_context io_ctx;
|
||||
auto opencl (nano::opencl_work::create (config.opencl_enable, config.opencl, logger, config.node.network_params.work));
|
||||
nano::work_pool opencl_work (config.node.network_params.network, config.node.work_threads, config.node.pow_sleep_interval, opencl ? [&opencl] (nano::work_version const version_a, nano::root const & root_a, uint64_t difficulty_a, std::atomic<int> & ticket_a) {
|
||||
return opencl->generate_work (version_a, root_a, difficulty_a, ticket_a);
|
||||
auto opencl = nano::opencl_work::create (config.opencl_enable, config.opencl, logger, config.node.network_params.work);
|
||||
nano::opencl_work_func_t opencl_work_func;
|
||||
if (opencl)
|
||||
{
|
||||
opencl_work_func = [&opencl] (nano::work_version const version_a, nano::root const & root_a, uint64_t difficulty_a, std::atomic<int> & ticket_a) {
|
||||
return opencl->generate_work (version_a, root_a, difficulty_a, ticket_a);
|
||||
};
|
||||
}
|
||||
: std::function<boost::optional<uint64_t> (nano::work_version const, nano::root const &, uint64_t, std::atomic<int> &)> (nullptr));
|
||||
nano::work_pool opencl_work (config.node.network_params.network, config.node.work_threads, config.node.pow_sleep_interval, opencl_work_func);
|
||||
try
|
||||
{
|
||||
// This avoids a blank prompt during any node initialization delays
|
||||
|
|
|
@ -615,11 +615,15 @@ int main (int argc, char * const * argv)
|
|||
{
|
||||
nano::logger logger;
|
||||
nano::opencl_config config (platform, device, threads);
|
||||
auto opencl (nano::opencl_work::create (true, config, logger, network_params.work));
|
||||
nano::work_pool work_pool{ network_params.network, 0, std::chrono::nanoseconds (0), opencl ? [&opencl] (nano::work_version const version_a, nano::root const & root_a, uint64_t difficulty_a, std::atomic<int> &) {
|
||||
return opencl->generate_work (version_a, root_a, difficulty_a);
|
||||
}
|
||||
: std::function<boost::optional<uint64_t> (nano::work_version const, nano::root const &, uint64_t, std::atomic<int> &)> (nullptr) };
|
||||
auto opencl = nano::opencl_work::create (true, config, logger, network_params.work);
|
||||
nano::opencl_work_func_t opencl_work_func;
|
||||
if (opencl)
|
||||
{
|
||||
opencl_work_func = [&opencl] (nano::work_version const version_a, nano::root const & root_a, uint64_t difficulty_a, std::atomic<int> &) {
|
||||
return opencl->generate_work (version_a, root_a, difficulty_a);
|
||||
};
|
||||
}
|
||||
nano::work_pool work_pool{ network_params.network, 0, std::chrono::nanoseconds (0), opencl_work_func };
|
||||
nano::change_block block (0, 0, nano::keypair ().prv, 0, 0);
|
||||
std::cerr << boost::str (boost::format ("Starting OpenCL generation profiling. Platform: %1%. Device: %2%. Threads: %3%. Difficulty: %4$#x (%5%x from base difficulty %6$#x)\n") % platform % device % threads % difficulty % nano::to_string (nano::difficulty::to_multiplier (difficulty, nano::work_thresholds::publish_full.base), 4) % nano::work_thresholds::publish_full.base);
|
||||
for (uint64_t i (0); true; ++i)
|
||||
|
|
|
@ -128,11 +128,15 @@ int run_wallet (QApplication & application, int argc, char * const * argv, std::
|
|||
std::shared_ptr<nano::node> node;
|
||||
std::shared_ptr<nano_qt::wallet> gui;
|
||||
nano::set_application_icon (application);
|
||||
auto opencl (nano::opencl_work::create (config.opencl_enable, config.opencl, logger, config.node.network_params.work));
|
||||
nano::work_pool work{ config.node.network_params.network, config.node.work_threads, config.node.pow_sleep_interval, opencl ? [&opencl] (nano::work_version const version_a, nano::root const & root_a, uint64_t difficulty_a, std::atomic<int> &) {
|
||||
return opencl->generate_work (version_a, root_a, difficulty_a);
|
||||
}
|
||||
: std::function<boost::optional<uint64_t> (nano::work_version const, nano::root const &, uint64_t, std::atomic<int> &)> (nullptr) };
|
||||
auto opencl = nano::opencl_work::create (config.opencl_enable, config.opencl, logger, config.node.network_params.work);
|
||||
nano::opencl_work_func_t opencl_work_func;
|
||||
if (opencl)
|
||||
{
|
||||
opencl_work_func = [&opencl] (nano::work_version const version_a, nano::root const & root_a, uint64_t difficulty_a, std::atomic<int> &) {
|
||||
return opencl->generate_work (version_a, root_a, difficulty_a);
|
||||
};
|
||||
}
|
||||
nano::work_pool work{ config.node.network_params.network, config.node.work_threads, config.node.pow_sleep_interval, opencl_work_func };
|
||||
node = std::make_shared<nano::node> (io_ctx, data_path, config.node, work, flags);
|
||||
if (!node->init_error ())
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <nano/lib/work.hpp>
|
||||
#include <nano/lib/config.hpp>
|
||||
#include <nano/node/openclconfig.hpp>
|
||||
#include <nano/node/xorshift.hpp>
|
||||
|
||||
|
@ -22,12 +22,14 @@ namespace nano
|
|||
{
|
||||
extern bool opencl_loaded;
|
||||
class logger;
|
||||
|
||||
class opencl_platform
|
||||
{
|
||||
public:
|
||||
cl_platform_id platform;
|
||||
std::vector<cl_device_id> devices;
|
||||
};
|
||||
|
||||
class opencl_environment
|
||||
{
|
||||
public:
|
||||
|
@ -35,8 +37,10 @@ public:
|
|||
void dump (std::ostream & stream);
|
||||
std::vector<nano::opencl_platform> platforms;
|
||||
};
|
||||
|
||||
class root;
|
||||
class work_pool;
|
||||
|
||||
class opencl_work
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue