From 3549ab473aacee2d30d6b924d67b780591ef26a9 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 13 Jan 2021 10:56:14 -0800 Subject: [PATCH] ircd::cl: Load the pipe dynamically after configuring environment. --- include/ircd/cl.h | 3 ++- ircd/Makefile.am | 1 - ircd/cl.cc | 41 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/include/ircd/cl.h b/include/ircd/cl.h index 1c198548c..ef751dcb5 100644 --- a/include/ircd/cl.h +++ b/include/ircd/cl.h @@ -25,8 +25,9 @@ namespace ircd::cl struct data; struct work; + extern const info::versions version_api; + extern info::versions version_abi; extern log::log log; - extern const info::versions version_api, version_abi; string_view reflect_error(const int code) noexcept; diff --git a/ircd/Makefile.am b/ircd/Makefile.am index 0d25a1b53..f1594b44e 100644 --- a/ircd/Makefile.am +++ b/ircd/Makefile.am @@ -108,7 +108,6 @@ libircd_la_LIBADD = \ @JS_LIBS@ \ @ICU_LIBS@ \ @BOOST_LIBS@ \ - @OPENCL_LIBS@ \ @PBC_LIBS@ \ @SSL_LIBS@ \ @CRYPTO_LIBS@ \ diff --git a/ircd/cl.cc b/ircd/cl.cc index 944491d4c..c58577e8f 100644 --- a/ircd/cl.cc +++ b/ircd/cl.cc @@ -8,6 +8,7 @@ // copyright notice and this permission notice is present in all copies. The // full license for this software is available in the LICENSE file. +#include #include // Util @@ -23,13 +24,21 @@ namespace ircd::cl namespace ircd::cl { static const size_t + OPTION_MAX {8}, PLATFORM_MAX {8}, DEVICE_MAX {8}; static uint + options, platforms, devices[PLATFORM_MAX]; + static char + option[OPTION_MAX][256]; + + static void + *linkage; + static cl_platform_id platform[PLATFORM_MAX]; @@ -67,10 +76,7 @@ ircd::cl::version_api decltype(ircd::cl::version_abi) ircd::cl::version_abi { - "OpenCL", info::versions::ABI, 0, - { - 0, 0, 0 - } + "OpenCL", info::versions::ABI }; // @@ -79,6 +85,27 @@ ircd::cl::version_abi ircd::cl::init::init() { + const ctx::posix::enable_pthread enable_pthread; + + // Setup options + strlcpy{option[options++], "LP_NUM_THREADS=0"}; + strlcpy{option[options++], "MESA_GLSL_CACHE_DISABLE=true"}; + strlcpy{option[options++], "AMD_DEBUG=nogfx"}; + assert(options <= OPTION_MAX); + + // Configure options into the environment. TODO: XXX don't overwrite + while(options--) + sys::call(putenv, option[options]); + + // Load the pipe. + assert(!linkage); + if(!(linkage = dlopen("libOpenCL.so", RTLD_LAZY | RTLD_GLOBAL))) + return; + + // OpenCL sez platform=null is implementation defined. + info(clGetPlatformInfo, nullptr, CL_PLATFORM_VERSION, version_abi.string); + + // Get the platforms. call(clGetPlatformIDs, PLATFORM_MAX, platform, &platforms); char buf[4][128]; @@ -148,6 +175,10 @@ ircd::cl::init::init() ircd::cl::init::~init() noexcept { + if(!linkage) + return; + + const ctx::posix::enable_pthread enable_pthread; if(primary) { log::debug @@ -171,6 +202,8 @@ noexcept call(clReleaseContext, primary); primary = nullptr; } + + dlclose(linkage); } //