From d3d866c92fd568f5c14b0e6c254cd2cd0e8573f2 Mon Sep 17 00:00:00 2001 From: clemahieu Date: Tue, 19 Apr 2016 21:17:25 -0500 Subject: [PATCH] Logging opencl diagnostics also to log file. --- rai/node/node.cpp | 5 ++++- rai/node/openclwork.cpp | 21 ++++++++++++--------- rai/node/openclwork.hpp | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/rai/node/node.cpp b/rai/node/node.cpp index 6788eedd..3ab1595b 100644 --- a/rai/node/node.cpp +++ b/rai/node/node.cpp @@ -2479,7 +2479,10 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) rai::opencl_environment environment (error); if (!error) { - environment.dump (); + environment.dump (std::cout); + std::stringstream stream; + environment.dump (stream); + BOOST_LOG (node.logging.log) << stream.str (); } else { diff --git a/rai/node/openclwork.cpp b/rai/node/openclwork.cpp index 3ecc3b71..0048cda2 100644 --- a/rai/node/openclwork.cpp +++ b/rai/node/openclwork.cpp @@ -411,7 +411,7 @@ rai::opencl_environment::opencl_environment (bool & error_a) } } -void rai::opencl_environment::dump () +void rai::opencl_environment::dump (std::ostream & stream) { auto index (0); auto device_count (0); @@ -419,30 +419,30 @@ void rai::opencl_environment::dump () { device_count += i.devices.size (); } - std::cout << boost::str (boost::format ("Found %1% platforms and %2% devices\n") % platforms.size () % device_count); + stream << boost::str (boost::format ("OpenCL found %1% platforms and %2% devices\n") % platforms.size () % device_count); for (auto i (platforms.begin ()), n (platforms.end ()); i != n; ++i, ++index) { std::vector queries = {CL_PLATFORM_PROFILE, CL_PLATFORM_VERSION, CL_PLATFORM_NAME, CL_PLATFORM_VENDOR, CL_PLATFORM_EXTENSIONS}; - std::cout << "Platform: " << index << std::endl; + stream << "Platform: " << index << std::endl; for (auto j (queries.begin ()), m (queries.end ()); j != m; ++j) { size_t platformInfoCount = 0; clGetPlatformInfo(i->platform, *j, 0, nullptr, &platformInfoCount); std::vector info (platformInfoCount); clGetPlatformInfo(i->platform, *j, info.size (), info.data (), nullptr); - std::cout << info.data () << std::endl; + stream << info.data () << std::endl; } for (auto j (i->devices.begin ()), m (i->devices.end ()); j != m; ++j) { std::vector queries = {CL_DEVICE_NAME, CL_DEVICE_VENDOR, CL_DEVICE_PROFILE}; - std::cout << "Device: " << j - i->devices.begin () << std::endl; + stream << "Device: " << j - i->devices.begin () << std::endl; for (auto k (queries.begin ()), o (queries.end ()); k != o; ++k) { size_t platformInfoCount = 0; clGetDeviceInfo(*j, *k, 0, nullptr, &platformInfoCount); std::vector info (platformInfoCount); clGetDeviceInfo(*j, *k, info.size (), info.data (), nullptr); - std::cout << '\t' << info.data () << std::endl; + stream << '\t' << info.data () << std::endl; } size_t deviceTypeCount = 0; clGetDeviceInfo(*j, CL_DEVICE_TYPE, 0, nullptr, &deviceTypeCount); @@ -470,18 +470,18 @@ void rai::opencl_environment::dump () device_type_string = "Unknown"; break; } - std::cout << '\t' << device_type_string << std::endl; + stream << '\t' << device_type_string << std::endl; size_t compilerAvailableCount = 0; clGetDeviceInfo(*j, CL_DEVICE_COMPILER_AVAILABLE, 0, nullptr, &compilerAvailableCount); std::vector compilerAvailableInfo (compilerAvailableCount); clGetDeviceInfo(*j, CL_DEVICE_COMPILER_AVAILABLE, compilerAvailableCount, compilerAvailableInfo.data (), 0); - std::cout << '\t' << "Compiler available: " << (compilerAvailableInfo [0] ? "true" : "false") << std::endl; + stream << '\t' << "Compiler available: " << (compilerAvailableInfo [0] ? "true" : "false") << std::endl; size_t computeUnitsAvailableCount = 0; clGetDeviceInfo(*j, CL_DEVICE_MAX_COMPUTE_UNITS, 0, nullptr, &computeUnitsAvailableCount); std::vector computeUnitsAvailableInfo (computeUnitsAvailableCount); clGetDeviceInfo(*j, CL_DEVICE_MAX_COMPUTE_UNITS, computeUnitsAvailableCount, computeUnitsAvailableInfo.data (), 0); uint64_t computeUnits (computeUnitsAvailableInfo [0] | (computeUnitsAvailableInfo [1] << 8) | (computeUnitsAvailableInfo [2] << 16) | (computeUnitsAvailableInfo [3] << 24)); - std::cout << '\t' << "Compute units available: " << computeUnits << std::endl; + stream << '\t' << "Compute units available: " << computeUnits << std::endl; } } } @@ -767,6 +767,9 @@ std::unique_ptr rai::opencl_work::create (bool create_a, rai: { auto error (false); rai::opencl_environment environment (error); + std::stringstream stream; + environment.dump (stream); + BOOST_LOG (logging_a.log) << stream.str (); if (!error) { result.reset (new rai::opencl_work (error, config_a, environment, logging_a)); diff --git a/rai/node/openclwork.hpp b/rai/node/openclwork.hpp index e25c6df2..a4f1b6de 100644 --- a/rai/node/openclwork.hpp +++ b/rai/node/openclwork.hpp @@ -28,7 +28,7 @@ class opencl_environment { public: opencl_environment (bool &); - void dump (); + void dump (std::ostream & stream); std::vector platforms; }; union uint256_union;