Making opencl opaque to work_pool.

This commit is contained in:
clemahieu 2017-12-21 15:21:37 -06:00
commit badba2ab65
6 changed files with 28 additions and 16 deletions

View file

@ -2,7 +2,6 @@
#include <rai/node/node.hpp>
#include <rai/node/wallet.hpp>
#include <rai/node/openclwork.hpp>
TEST (work, one)
{
@ -56,10 +55,13 @@ TEST (work, DISABLED_opencl)
{
rai::logging logging;
logging.init (rai::unique_path ());
auto work (rai::opencl_work::create (true, {0, 1, 1024 * 1024}, logging));
if (work != nullptr)
auto opencl (rai::opencl_work::create (true, {0, 1, 1024 * 1024}, logging));
if (opencl != nullptr)
{
rai::work_pool pool (std::numeric_limits <unsigned>::max (), std::move (work));
rai::work_pool pool (std::numeric_limits <unsigned>::max (), opencl ? [&opencl] (rai::uint256_union const & root_a)
{
return opencl->generate_work (root_a);
} : std::function <boost::optional <uint64_t> (rai::uint256_union const &)> (nullptr));
ASSERT_NE (nullptr, pool.opencl);
rai::uint256_union root;
for (auto i (0); i < 1; ++i)

View file

@ -1,7 +1,6 @@
#include <rai/node/work.hpp>
#include <rai/node/xorshift.hpp>
#include <rai/node/openclwork.hpp>
#include <future>
@ -27,10 +26,10 @@ uint64_t rai::work_value (rai::block_hash const & root_a, uint64_t work_a)
return result;
}
rai::work_pool::work_pool (unsigned max_threads_a, std::unique_ptr <rai::opencl_work> opencl_a) :
rai::work_pool::work_pool (unsigned max_threads_a, std::function <boost::optional<uint64_t> (rai::uint256_union const &)> opencl_a) :
ticket (0),
done (false),
opencl (std::move (opencl_a))
opencl (opencl_a)
{
static_assert (ATOMIC_INT_LOCK_FREE == 2, "Atomic int needed");
auto count (rai::rai_network == rai::rai_networks::rai_test_network ? 1 : std::max (1u, std::min (max_threads_a, std::thread::hardware_concurrency ())));
@ -156,9 +155,9 @@ void rai::work_pool::generate (rai::uint256_union const & root_a, std::function
{
assert (!root_a.is_zero ());
boost::optional <uint64_t> result;
if (opencl != nullptr)
if (opencl)
{
result = opencl->generate_work (root_a);
result = opencl (root_a);
}
if (!result)
{

View file

@ -18,7 +18,7 @@ class opencl_work;
class work_pool
{
public:
work_pool (unsigned, std::unique_ptr <rai::opencl_work>);
work_pool (unsigned, std::function <boost::optional <uint64_t> (rai::uint256_union const &)> = nullptr);
~work_pool ();
void loop (uint64_t);
void stop ();
@ -31,7 +31,7 @@ public:
std::list <std::pair <rai::uint256_union, std::function <void (boost::optional <uint64_t> const &)>>> pending;
std::mutex mutex;
std::condition_variable producer_condition;
std::unique_ptr <rai::opencl_work> opencl;
std::function <boost::optional<uint64_t> (rai::uint256_union const &)> opencl;
rai::observer_set <bool> work_observers;
// Local work threshold for rate-limiting publishing blocks. ~5 seconds of work.
static uint64_t const publish_test_threshold = 0xff00000000000000;

View file

@ -107,10 +107,14 @@ void rai_daemon::daemon::run (boost::filesystem::path const & data_path)
config.node.logging.init (data_path);
config_file.close ();
boost::asio::io_service service;
rai::work_pool work (config.node.work_threads, rai::opencl_work::create (config.opencl_enable, config.opencl, config.node.logging));
auto opencl (rai::opencl_work::create (config.opencl_enable, config.opencl, config.node.logging));
rai::work_pool opencl_work (config.node.work_threads, opencl ? [&opencl] (rai::uint256_union const & root_a)
{
return opencl->generate_work (root_a);
} : std::function <boost::optional <uint64_t> (rai::uint256_union const &)> (nullptr));
rai::alarm alarm (service);
rai::node_init init;
auto node (std::make_shared <rai::node> (init, service, data_path, alarm, config.node, work));
auto node (std::make_shared <rai::node> (init, service, data_path, alarm, config.node, opencl_work));
if (!init.error ())
{
node->start ();

View file

@ -317,8 +317,11 @@ int main (int argc, char * const * argv)
if (!error)
{
rai::logging logging;
auto work (rai::opencl_work::create (true, {platform, device, threads}, logging));
rai::work_pool work_pool (std::numeric_limits <unsigned>::max (), std::move (work));
auto opencl (rai::opencl_work::create (true, {platform, device, threads}, logging));
rai::work_pool work_pool (std::numeric_limits <unsigned>::max (), opencl ? [&opencl] (rai::uint256_union const & root_a)
{
return opencl->generate_work (root_a);
} : std::function <boost::optional <uint64_t> (rai::uint256_union const &)> (nullptr));
rai::change_block block (0, 0, rai::keypair ().prv, 0, 0);
std::cerr << boost::str (boost::format ("Starting OpenCL generation profiling. Platform: %1%. Device: %2%. Threads: %3%\n") % platform % device % threads);
for (uint64_t i (0); true; ++i)

View file

@ -211,7 +211,11 @@ int run_wallet (QApplication & application, int argc, char * const * argv, boost
std::shared_ptr <rai::node> node;
std::shared_ptr <rai_qt::wallet> gui;
rai::set_application_icon (application);
rai::work_pool work (config.node.work_threads, rai::opencl_work::create (config.opencl_enable, config.opencl, config.node.logging));
auto opencl (rai::opencl_work::create (config.opencl_enable, config.opencl, config.node.logging));
rai::work_pool work (config.node.work_threads, opencl ? [&opencl] (rai::uint256_union const & root_a)
{
return opencl->generate_work (root_a);
} : std::function <boost::optional <uint64_t> (rai::uint256_union const &)> (nullptr));
rai::alarm alarm (service);
rai::node_init init;
node = std::make_shared <rai::node> (init, service, data_path, alarm, config.node, work);