0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

ircd:🆑 Load the pipe dynamically after configuring environment.

This commit is contained in:
Jason Volk 2021-01-13 10:56:14 -08:00
parent c34045c9d8
commit 3549ab473a
3 changed files with 39 additions and 6 deletions

View file

@ -25,8 +25,9 @@ namespace ircd::cl
struct data; struct data;
struct work; struct work;
extern const info::versions version_api;
extern info::versions version_abi;
extern log::log log; extern log::log log;
extern const info::versions version_api, version_abi;
string_view reflect_error(const int code) noexcept; string_view reflect_error(const int code) noexcept;

View file

@ -108,7 +108,6 @@ libircd_la_LIBADD = \
@JS_LIBS@ \ @JS_LIBS@ \
@ICU_LIBS@ \ @ICU_LIBS@ \
@BOOST_LIBS@ \ @BOOST_LIBS@ \
@OPENCL_LIBS@ \
@PBC_LIBS@ \ @PBC_LIBS@ \
@SSL_LIBS@ \ @SSL_LIBS@ \
@CRYPTO_LIBS@ \ @CRYPTO_LIBS@ \

View file

@ -8,6 +8,7 @@
// copyright notice and this permission notice is present in all copies. The // copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file. // full license for this software is available in the LICENSE file.
#include <dlfcn.h>
#include <CL/cl.h> #include <CL/cl.h>
// Util // Util
@ -23,13 +24,21 @@ namespace ircd::cl
namespace ircd::cl namespace ircd::cl
{ {
static const size_t static const size_t
OPTION_MAX {8},
PLATFORM_MAX {8}, PLATFORM_MAX {8},
DEVICE_MAX {8}; DEVICE_MAX {8};
static uint static uint
options,
platforms, platforms,
devices[PLATFORM_MAX]; devices[PLATFORM_MAX];
static char
option[OPTION_MAX][256];
static void
*linkage;
static cl_platform_id static cl_platform_id
platform[PLATFORM_MAX]; platform[PLATFORM_MAX];
@ -67,10 +76,7 @@ ircd::cl::version_api
decltype(ircd::cl::version_abi) decltype(ircd::cl::version_abi)
ircd::cl::version_abi ircd::cl::version_abi
{ {
"OpenCL", info::versions::ABI, 0, "OpenCL", info::versions::ABI
{
0, 0, 0
}
}; };
// //
@ -79,6 +85,27 @@ ircd::cl::version_abi
ircd::cl::init::init() 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); call(clGetPlatformIDs, PLATFORM_MAX, platform, &platforms);
char buf[4][128]; char buf[4][128];
@ -148,6 +175,10 @@ ircd::cl::init::init()
ircd::cl::init::~init() ircd::cl::init::~init()
noexcept noexcept
{ {
if(!linkage)
return;
const ctx::posix::enable_pthread enable_pthread;
if(primary) if(primary)
{ {
log::debug log::debug
@ -171,6 +202,8 @@ noexcept
call(clReleaseContext, primary); call(clReleaseContext, primary);
primary = nullptr; primary = nullptr;
} }
dlclose(linkage);
} }
// //