0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

ircd:🆑 Cleanup / split library linkage to private memfun; bind now.

Bind now to prevent issues from lazy binding on different threads and
when overriding with custom builds of mesa/icd.
This commit is contained in:
Jason Volk 2022-03-05 14:09:02 -08:00
parent d817536e23
commit 729092d410
2 changed files with 57 additions and 36 deletions

View file

@ -289,8 +289,10 @@ class ircd::cl::init
{
size_t init_platforms();
size_t init_devices();
size_t init_pipes();
void fini_pipes();
size_t init_ctxs();
bool init_libs();
void fini_ctxs();
void fini_libs();
public:
init();

View file

@ -226,13 +226,56 @@ ircd::cl::init::init()
return;
}
const ctx::posix::enable_pthread enable_pthread;
// Link the libraries.
if(!init_libs())
return;
// Get the platforms.
if(!init_platforms())
return;
// Report the platforms.
log_platform_info();
// Get the devices.
if(!init_devices())
return;
// Report the devices.
log_dev_info();
// Various other inits.
init_ctxs();
}
ircd::cl::init::~init()
noexcept
{
if(!linkage)
return;
log::debug
{
log, "Shutting down OpenCL...",
};
const ctx::posix::enable_pthread enable_pthread;
fini_ctxs();
fini_libs();
}
bool
ircd::cl::init::init_libs()
{
const std::string &path
{
cl::path
};
if(path.empty())
return;
return false;
// Setup options
for(const auto &item : envs)
@ -248,43 +291,19 @@ ircd::cl::init::init()
sys::call(putenv, option[options++]);
}
const ctx::posix::enable_pthread enable_pthread;
// Load the pipe.
assert(!linkage);
if(!(linkage = dlopen(path.c_str(), RTLD_LAZY | RTLD_GLOBAL)))
return;
if(!(linkage = dlopen(path.c_str(), RTLD_NOW | RTLD_GLOBAL)))
return false;
// Get the platforms.
init_platforms();
// Report the platforms.
log_platform_info();
// Get the devices.
init_devices();
// Report the devices.
log_dev_info();
// Various other inits.
init_pipes();
return true;
}
ircd::cl::init::~init()
noexcept
void
ircd::cl::init::fini_libs()
{
if(!linkage)
return;
const ctx::posix::enable_pthread enable_pthread;
log::debug
{
log, "Shutting down OpenCL...",
};
fini_pipes();
dlclose(linkage);
if(likely(linkage))
dlclose(linkage);
}
size_t
@ -348,7 +367,7 @@ ircd::cl::init::init_devices()
}
size_t
ircd::cl::init::init_pipes()
ircd::cl::init::init_ctxs()
{
// Gather all devices we'll use.
size_t _devs {0};
@ -398,7 +417,7 @@ ircd::cl::init::init_pipes()
}
void
ircd::cl::init::fini_pipes()
ircd::cl::init::fini_ctxs()
{
if(primary)
work::fini();