2021-01-04 11:29:40 +01:00
|
|
|
// The Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2021 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
2021-01-13 19:56:14 +01:00
|
|
|
#include <dlfcn.h>
|
2021-01-04 11:29:40 +01:00
|
|
|
#include <CL/cl.h>
|
2021-10-04 00:28:27 +02:00
|
|
|
#include <CL/cl_ext.h>
|
2021-01-04 11:29:40 +01:00
|
|
|
|
2021-01-05 23:50:53 +01:00
|
|
|
// Util
|
2021-01-04 11:29:40 +01:00
|
|
|
namespace ircd::cl
|
|
|
|
{
|
2021-01-05 23:50:53 +01:00
|
|
|
static bool is_error(const int &code) noexcept;
|
|
|
|
static int throw_on_error(const int &code);
|
2022-03-05 21:28:07 +01:00
|
|
|
template<int maybe = CL_SUCCESS, class func, class... args> static int call(func&&, args&&...);
|
|
|
|
template<class T = string_view, int maybe = CL_SUCCESS, class F, class id, class param> static T info(F&&, const id &, const param &, const mutable_buffer &, T default_ = {});
|
|
|
|
template<class T = string_view, int maybe = CL_SUCCESS, class F, class id0, class id1, class param> static T info(F&&, const id0 &, const id1 &, const param &, const mutable_buffer &, T default_ = {});
|
2021-04-03 21:25:59 +02:00
|
|
|
|
2022-05-01 21:03:11 +02:00
|
|
|
static string_view version_str(const mutable_buffer &, const cl_version);
|
2022-10-30 19:49:32 +01:00
|
|
|
static uint query_warp_size_amd(cl_device_id);
|
2021-04-03 21:25:59 +02:00
|
|
|
static uint query_warp_size(cl_context, cl_device_id);
|
2021-01-04 11:29:40 +01:00
|
|
|
}
|
|
|
|
|
2021-01-05 23:50:53 +01:00
|
|
|
// Runtime state
|
|
|
|
namespace ircd::cl
|
|
|
|
{
|
|
|
|
static const size_t
|
2021-01-13 19:56:14 +01:00
|
|
|
OPTION_MAX {8},
|
2021-01-05 23:50:53 +01:00
|
|
|
PLATFORM_MAX {8},
|
|
|
|
DEVICE_MAX {8};
|
|
|
|
|
|
|
|
static uint
|
2021-01-13 19:56:14 +01:00
|
|
|
options,
|
2021-01-05 23:50:53 +01:00
|
|
|
platforms,
|
|
|
|
devices[PLATFORM_MAX];
|
|
|
|
|
2021-01-13 19:56:14 +01:00
|
|
|
static char
|
|
|
|
option[OPTION_MAX][256];
|
|
|
|
|
|
|
|
static void
|
|
|
|
*linkage;
|
|
|
|
|
2021-01-05 23:50:53 +01:00
|
|
|
static cl_platform_id
|
|
|
|
platform[PLATFORM_MAX];
|
|
|
|
|
|
|
|
static cl_device_id
|
|
|
|
device[PLATFORM_MAX][DEVICE_MAX];
|
|
|
|
|
2021-10-04 00:28:27 +02:00
|
|
|
static struct version
|
|
|
|
{
|
|
|
|
int major, minor;
|
|
|
|
}
|
|
|
|
api[PLATFORM_MAX][DEVICE_MAX];
|
|
|
|
|
2022-09-27 21:23:43 +02:00
|
|
|
static uint
|
|
|
|
warp_size[PLATFORM_MAX][DEVICE_MAX];
|
|
|
|
|
2021-01-05 23:50:53 +01:00
|
|
|
static cl_context
|
|
|
|
primary;
|
|
|
|
|
2021-03-26 02:36:36 +01:00
|
|
|
extern struct stats
|
|
|
|
primary_stats;
|
|
|
|
|
2021-01-05 23:50:53 +01:00
|
|
|
static cl_command_queue
|
|
|
|
queue[PLATFORM_MAX][DEVICE_MAX];
|
|
|
|
|
|
|
|
static void handle_notify(const char *, const void *, size_t, void *) noexcept;
|
|
|
|
}
|
|
|
|
|
2021-03-26 02:36:36 +01:00
|
|
|
struct ircd::cl::stats
|
|
|
|
{
|
|
|
|
template<class T>
|
|
|
|
using item = ircd::stats::item<T>;
|
|
|
|
|
|
|
|
item<uint64_t>
|
2021-04-09 21:13:27 +02:00
|
|
|
sync_count,
|
|
|
|
flush_count,
|
2021-03-26 02:36:36 +01:00
|
|
|
alloc_count,
|
|
|
|
alloc_bytes,
|
|
|
|
dealloc_count,
|
|
|
|
dealloc_bytes,
|
2021-04-09 21:13:27 +02:00
|
|
|
work_waits,
|
|
|
|
work_waits_async,
|
|
|
|
work_errors,
|
2022-03-05 21:30:51 +01:00
|
|
|
work_completes,
|
2021-03-26 02:36:36 +01:00
|
|
|
exec_tasks,
|
|
|
|
exec_kern_tasks,
|
|
|
|
exec_kern_threads,
|
|
|
|
exec_kern_groups,
|
2021-04-09 21:13:27 +02:00
|
|
|
exec_write_tasks,
|
|
|
|
exec_write_bytes,
|
|
|
|
exec_read_tasks,
|
|
|
|
exec_read_bytes,
|
|
|
|
exec_copy_tasks,
|
|
|
|
exec_copy_bytes,
|
2021-03-26 02:36:36 +01:00
|
|
|
exec_barrier_tasks;
|
|
|
|
};
|
|
|
|
|
2021-01-05 23:50:53 +01:00
|
|
|
decltype(ircd::cl::log)
|
|
|
|
ircd::cl::log
|
|
|
|
{
|
|
|
|
"cl"
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::cl::version_api)
|
|
|
|
ircd::cl::version_api
|
2021-01-04 11:29:40 +01:00
|
|
|
{
|
|
|
|
"OpenCL", info::versions::API, CL_TARGET_OPENCL_VERSION,
|
|
|
|
{
|
2021-01-05 23:50:53 +01:00
|
|
|
#if defined(CL_VERSION_MAJOR) && defined(CL_VERSION_MINOR) && defined(CL_VERSION_PATCH)
|
|
|
|
CL_VERSION_MAJOR(CL_TARGET_OPENCL_VERSION),
|
|
|
|
CL_VERSION_MINOR(CL_TARGET_OPENCL_VERSION),
|
|
|
|
CL_VERSION_PATCH(CL_TARGET_OPENCL_VERSION),
|
|
|
|
#endif
|
2021-01-04 11:29:40 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-05 23:50:53 +01:00
|
|
|
decltype(ircd::cl::version_abi)
|
|
|
|
ircd::cl::version_abi
|
2021-01-04 11:29:40 +01:00
|
|
|
{
|
2021-01-13 19:56:14 +01:00
|
|
|
"OpenCL", info::versions::ABI
|
2021-01-04 11:29:40 +01:00
|
|
|
};
|
2021-01-05 23:50:53 +01:00
|
|
|
|
2021-01-16 01:40:42 +01:00
|
|
|
decltype(ircd::cl::enable)
|
|
|
|
ircd::cl::enable
|
|
|
|
{
|
|
|
|
{ "name", "ircd.cl.enable" },
|
2021-05-12 08:39:35 +02:00
|
|
|
{ "default", true },
|
2021-01-16 01:40:42 +01:00
|
|
|
{ "persist", false },
|
|
|
|
};
|
|
|
|
|
2021-03-20 21:41:25 +01:00
|
|
|
decltype(ircd::cl::profile_queue)
|
|
|
|
ircd::cl::profile_queue
|
|
|
|
{
|
2022-11-15 02:32:03 +01:00
|
|
|
{ "name", "ircd.cl.queue.profile" },
|
2021-03-20 21:41:25 +01:00
|
|
|
{ "default", false },
|
|
|
|
{ "persist", false },
|
|
|
|
};
|
|
|
|
|
2022-11-15 02:32:03 +01:00
|
|
|
decltype(ircd::cl::device_queue)
|
|
|
|
ircd::cl::device_queue
|
|
|
|
{
|
|
|
|
{ "name", "ircd.cl.queue.device" },
|
|
|
|
{ "default", true },
|
|
|
|
{ "persist", false },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::cl::queue_size)
|
|
|
|
ircd::cl::queue_size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.cl.queue.size" },
|
|
|
|
{ "default", long(1_MiB) },
|
|
|
|
{ "persist", false },
|
|
|
|
};
|
|
|
|
|
2022-09-27 21:26:35 +02:00
|
|
|
decltype(ircd::cl::intensity)
|
|
|
|
ircd::cl::intensity
|
2021-05-10 06:24:10 +02:00
|
|
|
{
|
2022-09-27 21:26:35 +02:00
|
|
|
{ "name", "ircd.cl.intensity" },
|
|
|
|
{ "default", 0L },
|
2021-05-10 06:24:10 +02:00
|
|
|
};
|
|
|
|
|
2021-10-28 00:21:14 +02:00
|
|
|
decltype(ircd::cl::watchdog_tsc)
|
|
|
|
ircd::cl::watchdog_tsc
|
|
|
|
{
|
|
|
|
{ "name", "ircd.cl.watchdog.tsc" },
|
|
|
|
{ "default", 268'435'456L },
|
|
|
|
};
|
|
|
|
|
2022-03-10 02:37:20 +01:00
|
|
|
decltype(ircd::cl::path)
|
|
|
|
ircd::cl::path
|
|
|
|
{
|
|
|
|
{ "name", "ircd.cl.path" },
|
|
|
|
{ "default", "libOpenCL.so" },
|
|
|
|
{ "persist", false },
|
|
|
|
};
|
|
|
|
|
2021-05-12 08:09:47 +02:00
|
|
|
decltype(ircd::cl::envs)
|
|
|
|
ircd::cl::envs
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "LP_NUM_THREADS" },
|
|
|
|
{ "default", "0" },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{ "name", "MESA_NO_MINMAX_CACHE" },
|
|
|
|
{ "default", "true" },
|
|
|
|
},
|
|
|
|
{
|
2023-04-17 03:48:05 +02:00
|
|
|
{ "name", "MESA_SHADER_CACHE_DISABLE" },
|
|
|
|
{ "default", "true" },
|
2021-05-12 08:09:47 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
{ "name", "AMD_DEBUG" },
|
|
|
|
{ "default", "nogfx,reserve_vmid" },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{ "name", "R600_DEBUG" },
|
|
|
|
{ "default", "forcedma" },
|
|
|
|
},
|
2022-04-04 22:17:02 +02:00
|
|
|
{
|
|
|
|
{ "name", "RADEON_THREAD" },
|
|
|
|
{ "default", "false" },
|
|
|
|
},
|
2021-05-12 08:09:47 +02:00
|
|
|
};
|
|
|
|
|
2021-12-28 22:33:35 +01:00
|
|
|
decltype(ircd::cl::primary_stats)
|
|
|
|
ircd::cl::primary_stats
|
|
|
|
{
|
|
|
|
{ { "name", "ircd.cl.sync.count" } },
|
|
|
|
{ { "name", "ircd.cl.flush.count" } },
|
|
|
|
{ { "name", "ircd.cl.alloc.count" } },
|
|
|
|
{ { "name", "ircd.cl.alloc.bytes" } },
|
|
|
|
{ { "name", "ircd.cl.dealloc.count" } },
|
|
|
|
{ { "name", "ircd.cl.dealloc.bytes" } },
|
|
|
|
{ { "name", "ircd.cl.work.waits" } },
|
|
|
|
{ { "name", "ircd.cl.work.waits.async" } },
|
|
|
|
{ { "name", "ircd.cl.work.errors" } },
|
2022-03-05 21:30:51 +01:00
|
|
|
{ { "name", "ircd.cl.work.completes" } },
|
2021-12-28 22:33:35 +01:00
|
|
|
{ { "name", "ircd.cl.exec.tasks" } },
|
|
|
|
{ { "name", "ircd.cl.exec.kern.tasks" } },
|
|
|
|
{ { "name", "ircd.cl.exec.kern.threads" } },
|
|
|
|
{ { "name", "ircd.cl.exec.kern.groups" } },
|
|
|
|
{ { "name", "ircd.cl.exec.write.tasks" } },
|
|
|
|
{ { "name", "ircd.cl.exec.write.bytes" } },
|
|
|
|
{ { "name", "ircd.cl.exec.read.tasks" } },
|
|
|
|
{ { "name", "ircd.cl.exec.read.bytes" } },
|
|
|
|
{ { "name", "ircd.cl.exec.copy.tasks" } },
|
|
|
|
{ { "name", "ircd.cl.exec.copy.bytes" } },
|
|
|
|
{ { "name", "ircd.cl.exec.barrier.tasks" } },
|
|
|
|
};
|
|
|
|
|
2021-01-05 23:50:53 +01:00
|
|
|
//
|
|
|
|
// init
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::cl::init::init()
|
|
|
|
{
|
2021-01-16 01:40:42 +01:00
|
|
|
if(!enable)
|
|
|
|
{
|
|
|
|
log::dwarning
|
|
|
|
{
|
|
|
|
log, "OpenCL hardware acceleration is not available or enabled."
|
|
|
|
};
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-30 18:31:06 +02:00
|
|
|
const ctx::posix::enable_pthread enable_pthread;
|
|
|
|
|
2022-03-05 23:09:02 +01:00
|
|
|
// Link the libraries.
|
|
|
|
if(!init_libs())
|
2022-08-27 04:56:08 +02:00
|
|
|
{
|
|
|
|
log::warning
|
|
|
|
{
|
|
|
|
log, "OpenCL hardware acceleration runtime failed to link."
|
|
|
|
};
|
|
|
|
|
2021-01-13 19:56:14 +01:00
|
|
|
return;
|
2022-08-27 04:56:08 +02:00
|
|
|
}
|
2021-01-13 19:56:14 +01:00
|
|
|
|
2021-10-04 00:28:27 +02:00
|
|
|
// Get the platforms.
|
2022-03-05 23:09:02 +01:00
|
|
|
if(!init_platforms())
|
2022-08-27 04:56:08 +02:00
|
|
|
{
|
|
|
|
log::warning
|
|
|
|
{
|
|
|
|
log, "OpenCL hardware acceleration platform not found."
|
|
|
|
};
|
|
|
|
|
2022-03-05 23:09:02 +01:00
|
|
|
return;
|
2022-08-27 04:56:08 +02:00
|
|
|
}
|
2021-10-04 00:28:27 +02:00
|
|
|
|
|
|
|
// Report the platforms.
|
|
|
|
log_platform_info();
|
|
|
|
|
|
|
|
// Get the devices.
|
2022-03-05 23:09:02 +01:00
|
|
|
if(!init_devices())
|
2022-08-27 04:56:08 +02:00
|
|
|
{
|
|
|
|
log::warning
|
|
|
|
{
|
|
|
|
log, "OpenCL hardware acceleration device not found."
|
|
|
|
};
|
|
|
|
|
2022-03-05 23:09:02 +01:00
|
|
|
return;
|
2022-08-27 04:56:08 +02:00
|
|
|
}
|
2021-10-04 00:28:27 +02:00
|
|
|
|
|
|
|
// Various other inits.
|
2022-03-05 23:09:02 +01:00
|
|
|
init_ctxs();
|
2022-05-01 21:16:29 +02:00
|
|
|
|
|
|
|
// Report the devices.
|
|
|
|
log_dev_info();
|
2021-10-04 00:28:27 +02:00
|
|
|
}
|
|
|
|
|
2022-05-26 21:00:07 +02:00
|
|
|
[[gnu::cold]]
|
2021-10-04 00:28:27 +02:00
|
|
|
ircd::cl::init::~init()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
if(!linkage)
|
|
|
|
return;
|
|
|
|
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "Shutting down OpenCL...",
|
|
|
|
};
|
|
|
|
|
2022-09-30 18:31:06 +02:00
|
|
|
const ctx::posix::enable_pthread enable_pthread;
|
2022-03-05 23:09:02 +01:00
|
|
|
fini_ctxs();
|
|
|
|
fini_libs();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::cl::init::init_libs()
|
|
|
|
{
|
2022-06-20 07:05:21 +02:00
|
|
|
const string_view path
|
2022-03-05 23:09:02 +01:00
|
|
|
{
|
|
|
|
cl::path
|
|
|
|
};
|
|
|
|
|
|
|
|
if(path.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Setup options
|
|
|
|
for(const auto &item : envs)
|
|
|
|
{
|
|
|
|
assert(options < OPTION_MAX);
|
|
|
|
fmt::sprintf
|
|
|
|
{
|
|
|
|
option[options], "%s=%s",
|
|
|
|
item.name,
|
|
|
|
string_view{item},
|
|
|
|
};
|
|
|
|
|
|
|
|
sys::call(putenv, option[options++]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the pipe.
|
|
|
|
assert(!linkage);
|
|
|
|
if(!(linkage = dlopen(path.c_str(), RTLD_NOW | RTLD_GLOBAL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::cl::init::fini_libs()
|
|
|
|
{
|
|
|
|
if(likely(linkage))
|
|
|
|
dlclose(linkage);
|
2021-10-04 00:28:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::cl::init::init_platforms()
|
2023-04-11 02:26:01 +02:00
|
|
|
try
|
2021-10-04 00:28:27 +02:00
|
|
|
{
|
2021-01-13 19:56:14 +01:00
|
|
|
// OpenCL sez platform=null is implementation defined.
|
2022-03-05 21:40:09 +01:00
|
|
|
constexpr auto ignore(CL_INVALID_PLATFORM);
|
|
|
|
info<string_view, ignore>(clGetPlatformInfo, nullptr, CL_PLATFORM_VERSION, version_abi.string);
|
2021-01-13 19:56:14 +01:00
|
|
|
|
|
|
|
// Get the platforms.
|
2021-01-05 23:50:53 +01:00
|
|
|
call(clGetPlatformIDs, PLATFORM_MAX, platform, &platforms);
|
|
|
|
|
2021-10-04 00:28:27 +02:00
|
|
|
return platforms;
|
|
|
|
}
|
2023-04-11 02:26:01 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::logf
|
|
|
|
{
|
|
|
|
log, log::level::DERROR,
|
|
|
|
"OpenCL platforms initialization :%s",
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2021-01-05 23:50:53 +01:00
|
|
|
|
2021-10-04 00:28:27 +02:00
|
|
|
size_t
|
|
|
|
ircd::cl::init::init_devices()
|
2023-04-11 02:26:01 +02:00
|
|
|
try
|
2021-10-04 00:28:27 +02:00
|
|
|
{
|
|
|
|
// Get the devices.
|
2021-01-05 23:50:53 +01:00
|
|
|
size_t devices_total(0);
|
|
|
|
for(size_t i(0); i < platforms; ++i)
|
|
|
|
{
|
|
|
|
static const auto type
|
|
|
|
{
|
|
|
|
CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_ACCELERATOR
|
|
|
|
};
|
|
|
|
|
2022-08-27 22:33:27 +02:00
|
|
|
// OpenCL sez 0 devices throws an error but we log a warning for now.
|
|
|
|
constexpr auto ignore(CL_DEVICE_NOT_FOUND);
|
|
|
|
call<ignore>(clGetDeviceIDs, platform[i], type, DEVICE_MAX, device[i], devices + i);
|
2021-01-05 23:50:53 +01:00
|
|
|
devices_total += devices[i];
|
|
|
|
}
|
|
|
|
|
2021-10-04 00:28:27 +02:00
|
|
|
// Gather the API versions for the devices.
|
|
|
|
for(size_t i(0); i < platforms; ++i)
|
2022-03-05 21:39:00 +01:00
|
|
|
for(size_t j(0); j < devices[i]; ++j) try
|
2021-10-04 00:28:27 +02:00
|
|
|
{
|
|
|
|
// OpenCL sez:
|
|
|
|
// OpenCL<space><major_version.minor_version><space><vendor-specific information>
|
2022-03-05 21:39:00 +01:00
|
|
|
string_view ver; char buf[256];
|
2021-10-04 00:28:27 +02:00
|
|
|
ver = info(clGetDeviceInfo, device[i][j], CL_DEVICE_VERSION, buf);
|
|
|
|
ver = lstrip(ver, "OpenCL ");
|
|
|
|
ver = split(ver, ' ').first;
|
|
|
|
const auto &[major, minor]
|
|
|
|
{
|
|
|
|
split(ver, '.')
|
|
|
|
};
|
|
|
|
|
|
|
|
api[i][j].major = lex_cast<uint>(major);
|
|
|
|
api[i][j].minor = lex_cast<uint>(minor);
|
|
|
|
}
|
2022-03-05 21:39:00 +01:00
|
|
|
catch(const error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "OpenCL [%u][%u] CL_DEVICE_VERSION :%s",
|
|
|
|
i, j,
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
}
|
2021-10-04 00:28:27 +02:00
|
|
|
|
|
|
|
return devices_total;
|
|
|
|
}
|
2023-04-11 02:26:01 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "OpenCL devices initialization :%s",
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2021-10-04 00:28:27 +02:00
|
|
|
|
|
|
|
size_t
|
2022-03-05 23:09:02 +01:00
|
|
|
ircd::cl::init::init_ctxs()
|
2021-10-04 00:28:27 +02:00
|
|
|
{
|
2021-01-05 23:50:53 +01:00
|
|
|
// Gather all devices we'll use.
|
|
|
|
size_t _devs {0};
|
|
|
|
cl_device_id _dev[DEVICE_MAX];
|
|
|
|
for(size_t i(0); i < platforms; ++i)
|
|
|
|
for(size_t j(0); j < devices[i]; ++j)
|
|
|
|
_dev[_devs++] = device[i][j];
|
|
|
|
|
|
|
|
// Create a context from gathered devices.
|
|
|
|
cl_int err {CL_SUCCESS};
|
|
|
|
cl_context_properties ctxprop {0};
|
|
|
|
primary = clCreateContext(&ctxprop, _devs, _dev, handle_notify, nullptr, &err);
|
|
|
|
throw_on_error(err);
|
|
|
|
|
2022-11-15 02:32:03 +01:00
|
|
|
// Device queue enabler
|
|
|
|
bool dev_queue
|
|
|
|
{
|
|
|
|
true
|
|
|
|
&& cl::device_queue // If enabled by conf
|
|
|
|
&& !cl::profile_queue // And not profiling (for now)
|
|
|
|
};
|
|
|
|
|
|
|
|
// Device queue support
|
2022-10-03 04:36:48 +02:00
|
|
|
char tmp[4];
|
|
|
|
for(size_t i(0); i < _devs; ++i)
|
|
|
|
dev_queue &= info<uint>(clGetDeviceInfo, _dev[i], CL_DEVICE_MAX_ON_DEVICE_QUEUES, tmp);
|
|
|
|
|
2022-11-15 02:32:03 +01:00
|
|
|
// Queue out-of-order execution
|
|
|
|
bool dev_ooe
|
|
|
|
{
|
|
|
|
dev_queue // tied to dev_queue
|
|
|
|
};
|
|
|
|
|
|
|
|
// Queue size in bytes
|
|
|
|
uint dev_queue_size
|
|
|
|
{
|
|
|
|
uint(cl::queue_size)
|
|
|
|
};
|
|
|
|
|
|
|
|
// Queue size limited by devices
|
|
|
|
for(size_t i(0); i < _devs; ++i)
|
|
|
|
{
|
|
|
|
const auto max_queue_size
|
|
|
|
{
|
|
|
|
info<uint>(clGetDeviceInfo, _dev[i], CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, tmp)
|
|
|
|
};
|
|
|
|
|
|
|
|
dev_queue_size = std::min(dev_queue_size, max_queue_size);
|
|
|
|
}
|
|
|
|
|
2022-10-03 04:36:48 +02:00
|
|
|
const uint prop[][2]
|
|
|
|
{
|
|
|
|
{ CL_QUEUE_SIZE, dev_queue_size },
|
2022-10-24 03:31:48 +02:00
|
|
|
{ CL_QUEUE_PROPERTIES, CL_QUEUE_ON_DEVICE & boolmask<uint>(dev_queue) },
|
|
|
|
{ CL_QUEUE_PROPERTIES, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE & boolmask<uint>(dev_ooe) },
|
|
|
|
{ CL_QUEUE_PROPERTIES, CL_QUEUE_PROFILING_ENABLE & boolmask<uint>(profile_queue) },
|
2022-10-03 04:36:48 +02:00
|
|
|
{ 0, 0 },
|
|
|
|
};
|
2021-04-10 01:00:19 +02:00
|
|
|
|
2022-10-03 04:36:48 +02:00
|
|
|
cl_queue_properties qprop[8] {0};
|
2022-10-24 03:31:48 +02:00
|
|
|
const auto qprops(sizeof(qprop) / sizeof(cl_queue_properties));
|
|
|
|
for(size_t i(0), j(0); j < qprops && (prop[i][0] || prop[i][1]); ++i)
|
2022-10-03 04:36:48 +02:00
|
|
|
if(prop[i][1])
|
|
|
|
{
|
|
|
|
qprop[j++] = prop[i][0];
|
|
|
|
qprop[j++] = prop[i][1];
|
|
|
|
}
|
2021-04-10 01:00:19 +02:00
|
|
|
|
|
|
|
// Create a queue for each device.
|
2021-01-05 23:50:53 +01:00
|
|
|
for(size_t i(0); i < platforms; ++i)
|
|
|
|
for(size_t j(0); j < devices[i]; ++j)
|
|
|
|
{
|
2022-10-03 04:36:48 +02:00
|
|
|
queue[i][j] = clCreateCommandQueueWithProperties(primary, device[i][j], qprop, &err);
|
2021-01-05 23:50:53 +01:00
|
|
|
throw_on_error(err);
|
|
|
|
}
|
2021-03-11 18:11:57 +01:00
|
|
|
|
2021-04-10 01:00:19 +02:00
|
|
|
// For any inits in the work subsystem.
|
2021-03-11 18:11:57 +01:00
|
|
|
work::init();
|
2021-10-04 00:28:27 +02:00
|
|
|
|
2022-09-27 21:23:43 +02:00
|
|
|
// Save the warp/wavefront size.
|
|
|
|
for(size_t i(0); i < platforms; ++i)
|
|
|
|
for(size_t j(0); j < devices[i]; ++j)
|
|
|
|
warp_size[i][j] = query_warp_size(primary, device[i][j]);
|
|
|
|
|
2021-10-04 00:28:27 +02:00
|
|
|
return _devs;
|
2021-01-05 23:50:53 +01:00
|
|
|
}
|
|
|
|
|
2021-10-04 00:28:27 +02:00
|
|
|
void
|
2022-03-05 23:09:02 +01:00
|
|
|
ircd::cl::init::fini_ctxs()
|
2021-01-05 23:50:53 +01:00
|
|
|
{
|
|
|
|
if(primary)
|
2021-03-11 18:11:57 +01:00
|
|
|
work::fini();
|
2021-01-08 09:53:12 +01:00
|
|
|
|
2021-01-05 23:50:53 +01:00
|
|
|
for(size_t i(0); i < PLATFORM_MAX; ++i)
|
|
|
|
for(size_t j(0); j < DEVICE_MAX; ++j)
|
|
|
|
if(queue[i][j])
|
|
|
|
{
|
|
|
|
call(clReleaseCommandQueue, queue[i][j]);
|
|
|
|
queue[i][j] = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(primary)
|
|
|
|
{
|
|
|
|
call(clReleaseContext, primary);
|
|
|
|
primary = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-22 19:18:25 +02:00
|
|
|
void
|
|
|
|
ircd::cl::log_platform_info()
|
|
|
|
{
|
|
|
|
for(size_t i(0); i < platforms; ++i)
|
|
|
|
log_platform_info(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::cl::log_platform_info(const uint i)
|
|
|
|
{
|
|
|
|
char buf[3][64];
|
|
|
|
char extbuf[320];
|
|
|
|
log::logf
|
|
|
|
{
|
|
|
|
log, log::level::DEBUG,
|
|
|
|
"OpenCL [%u][*] %-3d :%s :%s :%s :%s",
|
|
|
|
i,
|
|
|
|
CL_TARGET_OPENCL_VERSION,
|
|
|
|
info(clGetPlatformInfo, platform[i], CL_PLATFORM_VERSION, buf[0]),
|
|
|
|
info(clGetPlatformInfo, platform[i], CL_PLATFORM_VENDOR, buf[1]),
|
|
|
|
info(clGetPlatformInfo, platform[i], CL_PLATFORM_NAME, buf[2]),
|
|
|
|
info(clGetPlatformInfo, platform[i], CL_PLATFORM_EXTENSIONS, extbuf),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-03 21:25:59 +02:00
|
|
|
void
|
2021-05-01 23:29:38 +02:00
|
|
|
ircd::cl::log_dev_info()
|
2021-04-03 21:25:59 +02:00
|
|
|
{
|
2021-05-01 23:29:38 +02:00
|
|
|
for(size_t i(0); i < platforms; ++i)
|
|
|
|
log_dev_info(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::cl::log_dev_info(const uint i)
|
|
|
|
{
|
|
|
|
if(unlikely(i >= PLATFORM_MAX))
|
|
|
|
throw std::out_of_range
|
|
|
|
{
|
|
|
|
"Invalid platform identifier."
|
|
|
|
};
|
|
|
|
|
|
|
|
for(size_t j(0); j < devices[i]; ++j)
|
|
|
|
log_dev_info(i, j);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::cl::log_dev_info(const uint i,
|
|
|
|
const uint j)
|
|
|
|
{
|
|
|
|
if(unlikely(i >= PLATFORM_MAX || j >= DEVICE_MAX))
|
|
|
|
throw std::out_of_range
|
|
|
|
{
|
|
|
|
"Invalid platform or device identifier."
|
|
|
|
};
|
|
|
|
|
2021-04-03 21:25:59 +02:00
|
|
|
const auto &dev
|
|
|
|
{
|
|
|
|
device[i][j]
|
|
|
|
};
|
|
|
|
|
|
|
|
char buf[12][192];
|
|
|
|
char pbuf[8][64];
|
2021-05-01 20:45:35 +02:00
|
|
|
|
|
|
|
const auto type
|
|
|
|
{
|
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_TYPE, buf[0])
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto type_str
|
|
|
|
{
|
|
|
|
type & CL_DEVICE_TYPE_CPU?
|
|
|
|
"CPU"_sv:
|
|
|
|
type & CL_DEVICE_TYPE_GPU?
|
|
|
|
"GPU"_sv:
|
|
|
|
type & CL_DEVICE_TYPE_ACCELERATOR?
|
|
|
|
"APU"_sv:
|
|
|
|
"DEV"_sv
|
|
|
|
};
|
|
|
|
|
|
|
|
const fmt::bsprintf<32> head
|
|
|
|
{
|
2021-05-12 08:09:47 +02:00
|
|
|
"%s id:%u:%u",
|
2021-05-01 20:45:35 +02:00
|
|
|
type_str,
|
|
|
|
i,
|
|
|
|
j,
|
|
|
|
};
|
|
|
|
|
2022-09-30 18:35:11 +02:00
|
|
|
constexpr auto ignore(CL_INVALID_VALUE);
|
2022-05-01 21:03:11 +02:00
|
|
|
const uint numeric_ver[]
|
|
|
|
{
|
2022-09-30 18:35:11 +02:00
|
|
|
info<uint, ignore>(clGetDeviceInfo, dev, CL_DEVICE_NUMERIC_VERSION, buf[0]),
|
|
|
|
info<uint, ignore>(clGetDeviceInfo, dev, CL_DEVICE_OPENCL_C_NUMERIC_VERSION_KHR, buf[1]),
|
2022-05-01 21:03:11 +02:00
|
|
|
};
|
|
|
|
|
2021-04-03 21:25:59 +02:00
|
|
|
log::info
|
|
|
|
{
|
2022-05-01 21:03:11 +02:00
|
|
|
log, "%s cl:%03u clc:%s dev:%s :%s :%s :%s :%s",
|
2021-05-01 20:45:35 +02:00
|
|
|
string_view{head},
|
2021-04-03 21:25:59 +02:00
|
|
|
CL_TARGET_OPENCL_VERSION,
|
2022-05-01 21:03:11 +02:00
|
|
|
version_str(buf[0], numeric_ver[0]),
|
|
|
|
version_str(buf[1], numeric_ver[1]),
|
2022-03-05 21:40:09 +01:00
|
|
|
info(clGetDeviceInfo, dev, CL_DEVICE_VERSION, buf[2]),
|
2021-04-03 21:25:59 +02:00
|
|
|
info(clGetDeviceInfo, dev, CL_DRIVER_VERSION, buf[3]),
|
2022-03-05 21:40:09 +01:00
|
|
|
info(clGetDeviceInfo, dev, CL_DEVICE_VENDOR, buf[4]),
|
|
|
|
info(clGetDeviceInfo, dev, CL_DEVICE_NAME, buf[5]),
|
2021-04-03 21:25:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const auto wid
|
|
|
|
{
|
|
|
|
info<std::array<size_t, 3>>(clGetDeviceInfo, dev, CL_DEVICE_MAX_WORK_ITEM_SIZES, buf[0])
|
|
|
|
};
|
|
|
|
|
|
|
|
log::info
|
|
|
|
{
|
2022-10-31 00:22:18 +01:00
|
|
|
log, "%s %u$mHz %u$x[simd%u] %u$x[%lu:%lu]%d %u$d[%u$x%u$x%u]",
|
2021-05-01 20:45:35 +02:00
|
|
|
string_view{head},
|
2021-04-03 21:25:59 +02:00
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_MAX_CLOCK_FREQUENCY, buf[0]),
|
2022-10-31 00:22:18 +01:00
|
|
|
info<uint, CL_INVALID_VALUE>(clGetDeviceInfo, dev, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, buf[1], 0U),
|
|
|
|
info<uint, CL_INVALID_VALUE>(clGetDeviceInfo, dev, CL_DEVICE_SIMD_WIDTH_AMD, buf[2], 0U),
|
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_MAX_COMPUTE_UNITS, buf[3]),
|
2022-09-27 21:23:43 +02:00
|
|
|
warp_size[i][j],
|
2022-10-31 00:22:18 +01:00
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_MAX_WORK_GROUP_SIZE, buf[4]),
|
|
|
|
info<int>(clGetDeviceInfo, dev, CL_DEVICE_PARTITION_PROPERTIES, buf[5]),
|
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, buf[6]),
|
2021-04-03 21:25:59 +02:00
|
|
|
wid[0], wid[1], wid[2],
|
|
|
|
};
|
|
|
|
|
|
|
|
log::info
|
|
|
|
{
|
2022-10-31 00:22:18 +01:00
|
|
|
log, "%s %u$bit-%s %s line %s align %s page %s param %s alloc %s",
|
2021-05-01 20:45:35 +02:00
|
|
|
string_view{head},
|
2021-04-03 21:25:59 +02:00
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_ADDRESS_BITS, buf[0]),
|
|
|
|
info<bool>(clGetDeviceInfo, dev, CL_DEVICE_ENDIAN_LITTLE, buf[1])?
|
|
|
|
"LE"_sv: "BE"_sv,
|
|
|
|
info<bool>(clGetDeviceInfo, dev, CL_DEVICE_ERROR_CORRECTION_SUPPORT, buf[2])?
|
|
|
|
"ECC"_sv: "non-ECC"_sv,
|
2021-10-04 00:29:13 +02:00
|
|
|
pretty(pbuf[0], iec(info<uint>(clGetDeviceInfo, dev, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, buf[3]))),
|
|
|
|
pretty(pbuf[1], iec(info<uint>(clGetDeviceInfo, dev, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, buf[4]))),
|
|
|
|
pretty(pbuf[2], iec(info<uint>(clGetDeviceInfo, dev, CL_DEVICE_MEM_BASE_ADDR_ALIGN, buf[5]))),
|
2022-10-31 00:22:18 +01:00
|
|
|
pretty(pbuf[3], iec(info<uint>(clGetDeviceInfo, dev, CL_DEVICE_MAX_PARAMETER_SIZE, buf[6]))),
|
|
|
|
pretty(pbuf[4], iec(info<ulong>(clGetDeviceInfo, dev, CL_DEVICE_MAX_MEM_ALLOC_SIZE, buf[7]))),
|
2021-10-04 00:29:13 +02:00
|
|
|
};
|
|
|
|
|
2021-04-03 21:25:59 +02:00
|
|
|
log::info
|
|
|
|
{
|
2022-10-31 00:22:18 +01:00
|
|
|
log, "%s global %s type:%02x cache %s chans %u banks %u width %u",
|
2021-05-01 20:45:35 +02:00
|
|
|
string_view{head},
|
2021-04-03 21:25:59 +02:00
|
|
|
pretty(pbuf[0], iec(info<ulong>(clGetDeviceInfo, dev, CL_DEVICE_GLOBAL_MEM_SIZE, buf[0]))),
|
2022-10-31 00:22:18 +01:00
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, buf[1]),
|
|
|
|
pretty(pbuf[1], iec(info<ulong>(clGetDeviceInfo, dev, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, buf[2]))),
|
|
|
|
info<uint, CL_INVALID_VALUE>(clGetDeviceInfo, dev, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, buf[3], 0U),
|
|
|
|
info<uint, CL_INVALID_VALUE>(clGetDeviceInfo, dev, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, buf[4], 0U),
|
|
|
|
info<uint, CL_INVALID_VALUE>(clGetDeviceInfo, dev, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, buf[5], 0U),
|
|
|
|
};
|
|
|
|
|
|
|
|
log::info
|
|
|
|
{
|
|
|
|
log, "%s local %s type:%02x banks %u const %s consts %u",
|
|
|
|
string_view{head},
|
|
|
|
pretty(pbuf[0], iec(info<ulong>(clGetDeviceInfo, dev, CL_DEVICE_LOCAL_MEM_SIZE, buf[0]))),
|
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_LOCAL_MEM_TYPE, buf[1]),
|
|
|
|
info<uint, CL_INVALID_VALUE>(clGetDeviceInfo, dev, CL_DEVICE_LOCAL_MEM_BANKS_AMD, buf[2], 0U),
|
|
|
|
pretty(pbuf[1], iec(info<ulong>(clGetDeviceInfo, dev, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, buf[3]))),
|
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_MAX_CONSTANT_ARGS, buf[4]),
|
2021-04-06 00:09:48 +02:00
|
|
|
};
|
|
|
|
|
2022-03-05 21:40:09 +01:00
|
|
|
log::logf
|
2021-04-06 00:09:48 +02:00
|
|
|
{
|
2022-03-05 21:40:09 +01:00
|
|
|
log, log::level::DEBUG,
|
2022-10-31 00:22:18 +01:00
|
|
|
"%s char%u short%u half%u int%u float%u long%u double%u",
|
2021-05-01 20:45:35 +02:00
|
|
|
string_view{head},
|
2021-04-06 00:09:48 +02:00
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, buf[0]),
|
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, buf[1]),
|
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, buf[2]),
|
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, buf[3]),
|
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, buf[4]),
|
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, buf[5]),
|
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, buf[6]),
|
2022-03-05 21:40:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const bool native_kernel
|
|
|
|
(
|
|
|
|
CL_EXEC_NATIVE_KERNEL
|
|
|
|
& info<ulong>(clGetDeviceInfo, dev, CL_DEVICE_EXECUTION_CAPABILITIES, buf[0])
|
|
|
|
);
|
|
|
|
|
|
|
|
const auto il_version
|
|
|
|
(
|
|
|
|
native_kernel?
|
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_IL_VERSION, buf[1]): 0
|
|
|
|
);
|
|
|
|
|
|
|
|
log::logf
|
|
|
|
{
|
|
|
|
log, log::level::DEBUG,
|
2022-10-03 04:36:48 +02:00
|
|
|
"%s SPIR-V:%b:%u queues:%u events:%u pref:%u max:%u printf:%lu :%s",
|
2022-03-05 21:40:09 +01:00
|
|
|
string_view{head},
|
2021-04-06 00:09:48 +02:00
|
|
|
native_kernel,
|
2022-03-05 21:40:09 +01:00
|
|
|
il_version,
|
2022-10-03 04:36:48 +02:00
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_MAX_ON_DEVICE_QUEUES, buf[0]),
|
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_MAX_ON_DEVICE_EVENTS, buf[1]),
|
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, buf[2]),
|
|
|
|
info<uint>(clGetDeviceInfo, dev, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, buf[3]),
|
|
|
|
info<size_t>(clGetDeviceInfo, dev, CL_DEVICE_PRINTF_BUFFER_SIZE, buf[4]),
|
|
|
|
info(clGetDeviceInfo, dev, CL_DEVICE_OPENCL_C_VERSION, buf[5])
|
2021-04-03 21:25:59 +02:00
|
|
|
};
|
|
|
|
|
2021-09-15 10:42:43 +02:00
|
|
|
char extensions_buf[2048];
|
|
|
|
const string_view extensions
|
|
|
|
{
|
|
|
|
info(clGetDeviceInfo, dev, CL_DEVICE_EXTENSIONS, extensions_buf)
|
|
|
|
};
|
|
|
|
|
2021-05-01 20:45:35 +02:00
|
|
|
log::logf
|
2021-04-03 21:25:59 +02:00
|
|
|
{
|
2021-05-01 20:45:35 +02:00
|
|
|
log, log::level::DEBUG,
|
|
|
|
"%s :%s",
|
|
|
|
string_view{head},
|
2021-09-15 10:42:43 +02:00
|
|
|
extensions,
|
2021-04-03 21:25:59 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Silly quirks of OpenCL force us to setup a context, compile a program, and
|
|
|
|
/// instantiate a kernel to find out the warp/wavefront size characteristic.
|
|
|
|
/// Note that other thread-grouping characteristics are available from device
|
|
|
|
/// properties directly.
|
|
|
|
uint
|
|
|
|
ircd::cl::query_warp_size(cl_context context,
|
2022-10-30 19:49:32 +01:00
|
|
|
cl_device_id dev)
|
2022-05-01 21:16:29 +02:00
|
|
|
try
|
2021-04-03 21:25:59 +02:00
|
|
|
{
|
2022-10-30 19:49:32 +01:00
|
|
|
// Attempt to get this value the easy way from a device API.
|
|
|
|
uint ret(0);
|
|
|
|
if((ret = query_warp_size_amd(dev)))
|
|
|
|
return ret;
|
|
|
|
|
2021-04-03 21:25:59 +02:00
|
|
|
assert(primary);
|
2022-10-30 19:49:32 +01:00
|
|
|
assert(context == primary); //TODO: XXX
|
2021-04-03 21:25:59 +02:00
|
|
|
|
2022-10-30 19:49:32 +01:00
|
|
|
// Get this value the hard way from the cl_kernel API which requires
|
|
|
|
// building a program first and querying its properties.
|
2021-04-03 21:25:59 +02:00
|
|
|
cl::code code
|
|
|
|
{
|
2022-03-27 11:48:25 +02:00
|
|
|
"__kernel void ircd_test() {}"_sv
|
2021-04-03 21:25:59 +02:00
|
|
|
};
|
|
|
|
|
2022-01-23 20:56:21 +01:00
|
|
|
code.compile();
|
|
|
|
code.link();
|
|
|
|
|
2021-04-03 21:25:59 +02:00
|
|
|
cl::kern kern
|
|
|
|
{
|
|
|
|
code, "ircd_test"
|
|
|
|
};
|
|
|
|
|
2022-10-30 19:49:32 +01:00
|
|
|
ret = kern.preferred_group_size_multiple(device);
|
|
|
|
return ret;
|
2021-04-03 21:25:59 +02:00
|
|
|
}
|
2022-05-01 21:16:29 +02:00
|
|
|
catch(const ctx::interrupted &)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch(const ctx::terminated &)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::logf
|
|
|
|
{
|
2022-09-30 18:35:11 +02:00
|
|
|
log, log::level::WARNING,
|
2022-10-30 19:49:32 +01:00
|
|
|
"context(%p) device(%p) query warp size :%s",
|
2022-05-01 21:16:29 +02:00
|
|
|
static_cast<const void *>(context),
|
2022-10-30 19:49:32 +01:00
|
|
|
static_cast<const void *>(dev),
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint
|
|
|
|
ircd::cl::query_warp_size_amd(cl_device_id dev)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
char buf[4];
|
|
|
|
constexpr auto ign(CL_INVALID_VALUE);
|
|
|
|
return info<uint, ign>(clGetDeviceInfo, dev, CL_DEVICE_WAVEFRONT_WIDTH_AMD, buf, 0);
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "device(%p) query warp size (AMD) :%s",
|
|
|
|
static_cast<const void *>(dev),
|
2022-05-01 21:16:29 +02:00
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2021-04-03 21:25:59 +02:00
|
|
|
|
2022-05-01 21:03:11 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::cl::version_str(const mutable_buffer &buf,
|
|
|
|
const cl_version val)
|
|
|
|
{
|
|
|
|
return fmt::sprintf
|
|
|
|
{
|
|
|
|
buf, "%u.%u.%u",
|
|
|
|
CL_VERSION_MAJOR(val),
|
|
|
|
CL_VERSION_MINOR(val),
|
|
|
|
CL_VERSION_PATCH(val),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-01-08 09:53:12 +01:00
|
|
|
//
|
|
|
|
// interface
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::cl::sync()
|
|
|
|
{
|
2021-05-01 20:46:41 +02:00
|
|
|
if(unlikely(!primary))
|
|
|
|
return;
|
|
|
|
|
2021-01-08 09:53:12 +01:00
|
|
|
auto &q
|
|
|
|
{
|
|
|
|
queue[0][0]
|
|
|
|
};
|
|
|
|
|
|
|
|
call
|
|
|
|
(
|
|
|
|
clFinish, q
|
|
|
|
);
|
2021-04-09 21:13:27 +02:00
|
|
|
|
|
|
|
++primary_stats.sync_count;
|
2021-01-08 09:53:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::cl::flush()
|
|
|
|
{
|
|
|
|
auto &q
|
|
|
|
{
|
|
|
|
queue[0][0]
|
|
|
|
};
|
|
|
|
|
|
|
|
call
|
|
|
|
(
|
|
|
|
clFlush, q
|
|
|
|
);
|
2021-04-09 21:13:27 +02:00
|
|
|
|
|
|
|
++primary_stats.flush_count;
|
2021-01-08 09:53:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// exec
|
|
|
|
//
|
|
|
|
|
2021-03-11 18:11:57 +01:00
|
|
|
namespace ircd::cl
|
|
|
|
{
|
2021-03-21 01:45:20 +01:00
|
|
|
static const size_t _deps_list_max {32};
|
2021-03-13 00:50:27 +01:00
|
|
|
static thread_local cl_event _deps_list[_deps_list_max];
|
|
|
|
|
2022-06-21 03:21:17 +02:00
|
|
|
static cl_event *addressof_handle(cl::work *const &);
|
2021-10-15 23:57:31 +02:00
|
|
|
static void check_submit_blocking(cl::exec *const &, const exec::opts &);
|
2021-03-26 02:43:04 +01:00
|
|
|
static void handle_submitted(cl::exec *const &, const exec::opts &);
|
2021-03-13 00:50:27 +01:00
|
|
|
static vector_view<cl_event> make_deps_default(cl::work *const &, const exec::opts &);
|
|
|
|
static vector_view<cl_event> make_deps(cl::work *const &, const exec::opts &);
|
2021-03-11 18:11:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
decltype(ircd::util::instance_list<ircd::cl::work>::allocator)
|
|
|
|
ircd::util::instance_list<ircd::cl::work>::allocator
|
|
|
|
{};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
decltype(ircd::util::instance_list<ircd::cl::work>::list)
|
|
|
|
ircd::util::instance_list<ircd::cl::work>::list
|
|
|
|
{
|
|
|
|
allocator
|
|
|
|
};
|
|
|
|
|
2021-03-13 00:50:27 +01:00
|
|
|
decltype(ircd::cl::exec::opts_default)
|
|
|
|
ircd::cl::exec::opts_default;
|
|
|
|
|
|
|
|
ircd::cl::exec::exec(const opts &opts)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
auto &q
|
|
|
|
{
|
|
|
|
queue[0][0]
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto deps
|
|
|
|
{
|
|
|
|
make_deps(this, opts)
|
|
|
|
};
|
|
|
|
|
2021-03-17 23:50:38 +01:00
|
|
|
assert(!this->handle);
|
2021-03-13 00:50:27 +01:00
|
|
|
call
|
|
|
|
(
|
|
|
|
clEnqueueBarrierWithWaitList,
|
|
|
|
q,
|
|
|
|
deps.size(),
|
|
|
|
deps.size()? deps.data(): nullptr,
|
2022-06-21 03:21:17 +02:00
|
|
|
addressof_handle(this)
|
2021-03-13 00:50:27 +01:00
|
|
|
);
|
2021-03-26 02:36:36 +01:00
|
|
|
|
|
|
|
primary_stats.exec_barrier_tasks += 1;
|
2021-03-26 02:43:04 +01:00
|
|
|
handle_submitted(this, opts);
|
2021-03-13 00:50:27 +01:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "Exec Barrier :%s",
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2021-01-08 09:53:12 +01:00
|
|
|
ircd::cl::exec::exec(kern &kern,
|
2022-09-27 21:26:35 +02:00
|
|
|
const kern::range &range,
|
2021-03-13 00:50:27 +01:00
|
|
|
const opts &opts)
|
2021-01-08 09:53:12 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
size_t dim(0);
|
2022-09-27 21:26:35 +02:00
|
|
|
for(size_t i(0); i < range.global.size(); ++i)
|
|
|
|
dim += range.global[i] > 0 && dim == i;
|
2021-01-08 09:53:12 +01:00
|
|
|
|
2021-03-25 04:01:15 +01:00
|
|
|
if(!dim)
|
|
|
|
return;
|
|
|
|
|
2021-10-28 00:22:40 +02:00
|
|
|
if(unlikely(run::level != run::level::RUN))
|
|
|
|
throw unavailable
|
|
|
|
{
|
|
|
|
"Unable to submit work items in runlevel %s",
|
|
|
|
reflect(run::level),
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(run::level == run::level::RUN);
|
2021-03-11 18:11:57 +01:00
|
|
|
auto &q
|
|
|
|
{
|
|
|
|
queue[0][0]
|
|
|
|
};
|
|
|
|
|
2022-11-05 03:33:15 +01:00
|
|
|
auto &dev
|
|
|
|
{
|
|
|
|
device[0][0]
|
|
|
|
};
|
|
|
|
|
2021-03-13 00:50:27 +01:00
|
|
|
const auto deps
|
2021-01-08 09:53:12 +01:00
|
|
|
{
|
2021-03-13 00:50:27 +01:00
|
|
|
make_deps(this, opts)
|
2021-01-08 09:53:12 +01:00
|
|
|
};
|
|
|
|
|
2021-09-22 19:11:22 +02:00
|
|
|
assert(!this->object);
|
|
|
|
this->object = &kern;
|
|
|
|
|
2022-11-05 03:33:15 +01:00
|
|
|
const auto max_local_size
|
|
|
|
{
|
|
|
|
kern.group_size(dev)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto reqd_local_size
|
|
|
|
{
|
|
|
|
kern.compile_group_size(dev)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto hint_local_size
|
|
|
|
{
|
|
|
|
kern.preferred_group_size_multiple(dev)
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t local[dim];
|
|
|
|
for(size_t d(0); d < dim; ++d)
|
|
|
|
{
|
|
|
|
local[d] = reqd_local_size[d]?: range.local[d]?: hint_local_size;
|
|
|
|
local[d] = std::min(local[d], max_local_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t global_size{range.global[0]};
|
|
|
|
size_t local_size{local[0]};
|
2022-09-27 21:26:35 +02:00
|
|
|
for(size_t d(1); d < dim; ++d)
|
|
|
|
{
|
|
|
|
global_size *= range.global[d];
|
2022-11-05 03:33:15 +01:00
|
|
|
local_size *= local[d];
|
2022-09-27 21:26:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(global_size % local_size == 0);
|
|
|
|
const size_t groups
|
|
|
|
{
|
|
|
|
global_size / local_size
|
|
|
|
};
|
2021-03-26 02:36:36 +01:00
|
|
|
|
2022-09-27 21:26:35 +02:00
|
|
|
assert(groups > 0);
|
|
|
|
size_t intensity
|
|
|
|
{
|
|
|
|
cl::intensity?
|
|
|
|
std::max(opts.intensity, uint(cl::intensity)):
|
|
|
|
opts.intensity
|
|
|
|
};
|
2021-03-26 02:36:36 +01:00
|
|
|
|
2022-09-27 21:26:35 +02:00
|
|
|
if(intensity < groups)
|
|
|
|
while(intensity > 1 && groups % intensity != 0)
|
|
|
|
intensity--;
|
2021-03-26 02:36:36 +01:00
|
|
|
|
2022-09-27 21:26:35 +02:00
|
|
|
const size_t tasks
|
|
|
|
{
|
|
|
|
intensity && intensity < groups?
|
|
|
|
groups / intensity:
|
|
|
|
1
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(!this->handle);
|
|
|
|
for(size_t i(0); i < tasks; ++i)
|
|
|
|
{
|
|
|
|
kern::range sub_range(range);
|
|
|
|
for(size_t d(0); d < dim; ++d)
|
|
|
|
{
|
|
|
|
sub_range.global[d] /= tasks;
|
|
|
|
sub_range.offset[d] += sub_range.global[d] * i;
|
|
|
|
}
|
|
|
|
|
|
|
|
call
|
|
|
|
(
|
|
|
|
clEnqueueNDRangeKernel,
|
|
|
|
q,
|
|
|
|
cl_kernel(kern.handle),
|
|
|
|
dim,
|
|
|
|
sub_range.offset.data(),
|
|
|
|
sub_range.global.data(),
|
2022-11-05 03:33:15 +01:00
|
|
|
local + 0,
|
2022-09-27 21:26:35 +02:00
|
|
|
deps.size(),
|
|
|
|
deps.size()? deps.data(): nullptr,
|
|
|
|
i == tasks - 1? addressof_handle(this): nullptr
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
primary_stats.exec_kern_tasks += tasks;
|
2021-03-26 02:36:36 +01:00
|
|
|
primary_stats.exec_kern_threads += global_size;
|
2022-09-27 21:26:35 +02:00
|
|
|
primary_stats.exec_kern_groups += groups;
|
2021-03-26 02:43:04 +01:00
|
|
|
handle_submitted(this, opts);
|
2021-01-08 09:53:12 +01:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "Exec Kern :%s",
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2021-03-19 19:13:20 +01:00
|
|
|
ircd::cl::exec::exec(data &dst,
|
|
|
|
const data &src,
|
|
|
|
const opts &opts)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
auto &q
|
|
|
|
{
|
|
|
|
queue[0][0]
|
|
|
|
};
|
|
|
|
|
2021-09-22 19:11:22 +02:00
|
|
|
assert(src.handle);
|
|
|
|
assert(dst.handle);
|
2021-03-19 19:13:20 +01:00
|
|
|
const size_t size
|
|
|
|
{
|
2021-09-16 06:19:36 +02:00
|
|
|
opts.size == -1UL?
|
|
|
|
std::min(dst.size(), src.size()):
|
|
|
|
opts.size
|
2021-03-19 19:13:20 +01:00
|
|
|
};
|
|
|
|
|
2021-09-16 06:19:36 +02:00
|
|
|
if(!size)
|
|
|
|
return;
|
|
|
|
|
2021-09-22 19:11:22 +02:00
|
|
|
assert(!this->object);
|
|
|
|
this->object = &dst;
|
|
|
|
|
|
|
|
const auto deps
|
|
|
|
{
|
|
|
|
make_deps(this, opts)
|
|
|
|
};
|
|
|
|
|
2021-03-19 19:13:20 +01:00
|
|
|
assert(!this->handle);
|
|
|
|
call
|
|
|
|
(
|
|
|
|
clEnqueueCopyBuffer,
|
|
|
|
q,
|
|
|
|
cl_mem(src.handle),
|
|
|
|
cl_mem(dst.handle),
|
|
|
|
opts.offset[1],
|
|
|
|
opts.offset[0],
|
|
|
|
size,
|
|
|
|
deps.size(),
|
|
|
|
deps.size()? deps.data(): nullptr,
|
2022-06-21 03:21:17 +02:00
|
|
|
addressof_handle(this)
|
2021-03-19 19:13:20 +01:00
|
|
|
);
|
2021-03-26 02:36:36 +01:00
|
|
|
|
2021-04-09 21:13:27 +02:00
|
|
|
primary_stats.exec_copy_bytes += size;
|
|
|
|
primary_stats.exec_copy_tasks += 1;
|
2021-03-26 02:43:04 +01:00
|
|
|
handle_submitted(this, opts);
|
2021-03-19 19:13:20 +01:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "Exec Copy :%s",
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2021-01-08 09:53:12 +01:00
|
|
|
ircd::cl::exec::exec(data &data,
|
2022-03-19 23:15:23 +01:00
|
|
|
const std::memory_order order,
|
2021-03-13 00:50:27 +01:00
|
|
|
const opts &opts)
|
2021-01-08 09:53:12 +01:00
|
|
|
try
|
|
|
|
{
|
2022-04-23 04:20:48 +02:00
|
|
|
if(unlikely(run::level < run::level::RUN))
|
2021-10-28 00:22:40 +02:00
|
|
|
throw unavailable
|
|
|
|
{
|
|
|
|
"Unable to write to device in runlevel %s",
|
|
|
|
reflect(run::level),
|
|
|
|
};
|
|
|
|
|
2022-04-23 04:20:48 +02:00
|
|
|
assert(run::level >= run::level::RUN);
|
2022-03-19 23:15:23 +01:00
|
|
|
const auto max_size
|
2021-03-18 01:15:03 +01:00
|
|
|
{
|
2021-09-16 06:19:36 +02:00
|
|
|
opts.size == -1UL?
|
|
|
|
data.size():
|
|
|
|
opts.size
|
2021-03-18 01:15:03 +01:00
|
|
|
};
|
|
|
|
|
2022-03-19 23:15:23 +01:00
|
|
|
const auto size
|
2021-03-18 01:15:03 +01:00
|
|
|
{
|
2022-03-19 23:15:23 +01:00
|
|
|
size_t(opts.offset[0]) < max_size?
|
|
|
|
max_size - opts.offset[0]:
|
|
|
|
0UL
|
2021-03-29 19:26:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
assert(size_t(size) <= data.size());
|
2022-03-19 23:15:23 +01:00
|
|
|
assert(size_t(opts.offset[0]) <= data.size());
|
|
|
|
if(!size)
|
|
|
|
return;
|
2021-03-18 01:15:03 +01:00
|
|
|
|
2022-03-19 23:15:23 +01:00
|
|
|
bool read {false}, write {false}, invalidate {false};
|
|
|
|
bool blocking {opts.blocking};
|
|
|
|
switch(order)
|
2021-03-18 01:15:03 +01:00
|
|
|
{
|
2022-03-19 23:15:23 +01:00
|
|
|
case std::memory_order_relaxed:
|
|
|
|
return;
|
2021-03-18 01:15:03 +01:00
|
|
|
|
2022-03-19 23:15:23 +01:00
|
|
|
case std::memory_order_consume:
|
|
|
|
read = true;
|
|
|
|
break;
|
2021-03-26 02:36:36 +01:00
|
|
|
|
2022-03-19 23:15:23 +01:00
|
|
|
case std::memory_order_acquire:
|
|
|
|
read = true;
|
|
|
|
write = true;
|
|
|
|
break;
|
2021-03-18 01:15:03 +01:00
|
|
|
|
2022-03-19 23:15:23 +01:00
|
|
|
case std::memory_order_seq_cst:
|
|
|
|
read = true;
|
|
|
|
write = true;
|
|
|
|
blocking = true;
|
|
|
|
break;
|
2021-03-18 01:15:03 +01:00
|
|
|
|
2022-04-05 05:21:36 +02:00
|
|
|
case std::memory_order_acq_rel:
|
|
|
|
invalidate = true;
|
|
|
|
break;
|
|
|
|
|
2022-03-19 23:15:23 +01:00
|
|
|
case std::memory_order_release:
|
|
|
|
break;
|
|
|
|
}
|
2021-03-18 01:15:03 +01:00
|
|
|
|
2022-03-19 23:15:23 +01:00
|
|
|
const cl_map_flags flags
|
2021-03-18 01:15:03 +01:00
|
|
|
{
|
2022-03-19 23:15:23 +01:00
|
|
|
(boolmask<cl_map_flags>(read) & CL_MAP_READ) |
|
|
|
|
(boolmask<cl_map_flags>(write) & CL_MAP_WRITE) |
|
|
|
|
(boolmask<cl_map_flags>(invalidate) & CL_MAP_WRITE_INVALIDATE_REGION)
|
2021-03-18 01:15:03 +01:00
|
|
|
};
|
|
|
|
|
2022-03-19 23:15:23 +01:00
|
|
|
if(!flags && !data.mapped)
|
2021-09-16 06:19:36 +02:00
|
|
|
return;
|
|
|
|
|
2022-04-05 05:21:36 +02:00
|
|
|
assert(flags || data.mapped);
|
|
|
|
assert(!this->object);
|
|
|
|
this->object = &data;
|
|
|
|
|
2021-10-28 00:22:40 +02:00
|
|
|
auto &q
|
|
|
|
{
|
|
|
|
queue[0][0]
|
|
|
|
};
|
2021-03-29 19:26:57 +02:00
|
|
|
|
|
|
|
const auto deps
|
|
|
|
{
|
|
|
|
make_deps(this, opts)
|
2021-03-18 01:15:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
int err {CL_SUCCESS};
|
|
|
|
assert(!this->handle);
|
2022-03-19 23:15:23 +01:00
|
|
|
if(flags)
|
|
|
|
data.mapped = clEnqueueMapBuffer
|
2021-03-18 01:15:03 +01:00
|
|
|
(
|
|
|
|
q,
|
|
|
|
cl_mem(data.handle),
|
2022-03-19 23:15:23 +01:00
|
|
|
blocking,
|
2021-03-18 01:15:03 +01:00
|
|
|
flags,
|
2022-03-19 23:15:23 +01:00
|
|
|
opts.offset[0],
|
2021-03-18 01:15:03 +01:00
|
|
|
size,
|
|
|
|
deps.size(),
|
|
|
|
deps.size()? deps.data(): nullptr,
|
2022-06-21 03:21:17 +02:00
|
|
|
addressof_handle(this),
|
2021-03-18 01:15:03 +01:00
|
|
|
&err
|
2022-03-19 23:15:23 +01:00
|
|
|
);
|
|
|
|
else
|
2021-03-18 01:15:03 +01:00
|
|
|
call
|
|
|
|
(
|
|
|
|
clEnqueueUnmapMemObject,
|
|
|
|
q,
|
|
|
|
cl_mem(data.handle),
|
2022-03-19 23:15:23 +01:00
|
|
|
std::exchange(data.mapped, nullptr),
|
2021-03-18 01:15:03 +01:00
|
|
|
0, // deps
|
|
|
|
nullptr, // depslist
|
2022-06-21 03:21:17 +02:00
|
|
|
addressof_handle(this)
|
2021-03-18 01:15:03 +01:00
|
|
|
);
|
2021-03-26 02:36:36 +01:00
|
|
|
|
2022-03-19 23:15:23 +01:00
|
|
|
throw_on_error(err);
|
|
|
|
primary_stats.exec_read_bytes += read? size: 0;
|
|
|
|
primary_stats.exec_read_tasks += read;
|
|
|
|
primary_stats.exec_write_bytes += write || invalidate? size: 0;
|
|
|
|
primary_stats.exec_write_tasks += write || invalidate;
|
|
|
|
handle_submitted(this, opts);
|
|
|
|
assert(data.mapped || !flags);
|
|
|
|
assert(this->handle);
|
2021-03-18 01:15:03 +01:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
2022-08-27 04:56:08 +02:00
|
|
|
log, "Exec Map order:%d :%s",
|
|
|
|
int(order),
|
2021-03-18 01:15:03 +01:00
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2021-03-26 02:43:04 +01:00
|
|
|
void
|
|
|
|
ircd::cl::handle_submitted(cl::exec *const &exec,
|
|
|
|
const exec::opts &opts)
|
|
|
|
{
|
2021-10-28 00:22:40 +02:00
|
|
|
assert(run::level == run::level::RUN || run::level == run::level::QUIT);
|
|
|
|
|
2021-03-26 02:43:04 +01:00
|
|
|
primary_stats.exec_tasks += 1;
|
|
|
|
|
|
|
|
if(opts.flush)
|
|
|
|
cl::flush();
|
|
|
|
|
|
|
|
if(opts.sync)
|
|
|
|
cl::sync();
|
2021-05-10 06:24:10 +02:00
|
|
|
|
2021-10-15 23:57:31 +02:00
|
|
|
if(likely(!opts.blocking))
|
|
|
|
check_submit_blocking(exec, opts);
|
2021-03-26 02:43:04 +01:00
|
|
|
}
|
|
|
|
|
2021-10-28 00:21:14 +02:00
|
|
|
/// Checks if the OpenCL runtime blocked this thread to sound the alarms.
|
2021-10-15 23:57:31 +02:00
|
|
|
void
|
|
|
|
ircd::cl::check_submit_blocking(cl::exec *const &exec,
|
|
|
|
const exec::opts &opts)
|
|
|
|
{
|
2021-10-28 00:21:14 +02:00
|
|
|
const uint64_t &threshold
|
2021-10-15 23:57:31 +02:00
|
|
|
{
|
2021-10-28 00:21:14 +02:00
|
|
|
watchdog_tsc
|
2021-10-15 23:57:31 +02:00
|
|
|
};
|
|
|
|
|
2021-10-28 00:21:14 +02:00
|
|
|
if(!threshold)
|
|
|
|
return;
|
|
|
|
|
2021-10-15 23:57:31 +02:00
|
|
|
const auto submit_cycles
|
|
|
|
{
|
|
|
|
prof::cycles() - exec->ts
|
|
|
|
};
|
|
|
|
|
|
|
|
if(likely(submit_cycles < threshold))
|
|
|
|
return;
|
|
|
|
|
|
|
|
char nbuf[64];
|
|
|
|
const auto name
|
|
|
|
{
|
|
|
|
exec->name(nbuf)
|
|
|
|
};
|
|
|
|
|
|
|
|
char pbuf[32];
|
|
|
|
log::dwarning
|
|
|
|
{
|
|
|
|
log, "clEnqueue() kernel '%s' blocking the host for %s cycles on submit.",
|
2022-03-05 21:46:36 +01:00
|
|
|
name?: "<unnamed kernel or unknown command type>"_sv,
|
2021-10-15 23:57:31 +02:00
|
|
|
pretty(pbuf, si(submit_cycles), 1),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-13 00:50:27 +01:00
|
|
|
ircd::vector_view<cl_event>
|
|
|
|
ircd::cl::make_deps(cl::work *const &work,
|
|
|
|
const exec::opts &opts)
|
2021-03-11 18:11:57 +01:00
|
|
|
{
|
2022-10-03 04:36:48 +02:00
|
|
|
if(empty(opts.deps) && !opts.indep)
|
2021-03-13 00:50:27 +01:00
|
|
|
return make_deps_default(work, opts);
|
|
|
|
|
2021-03-19 07:24:41 +01:00
|
|
|
if(empty(opts.deps))
|
|
|
|
return {};
|
|
|
|
|
2021-03-11 18:11:57 +01:00
|
|
|
size_t ret(0);
|
2021-03-13 00:50:27 +01:00
|
|
|
vector_view<cl_event> out(_deps_list);
|
|
|
|
for(auto &exec : opts.deps)
|
|
|
|
out.at(ret++) = cl_event(exec.handle);
|
|
|
|
|
|
|
|
return vector_view<cl_event>
|
|
|
|
{
|
|
|
|
out, ret
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::vector_view<cl_event>
|
|
|
|
ircd::cl::make_deps_default(cl::work *const &work,
|
|
|
|
const exec::opts &opts)
|
|
|
|
{
|
|
|
|
size_t ret(0);
|
|
|
|
vector_view<cl_event> out(_deps_list);
|
2021-03-11 18:11:57 +01:00
|
|
|
for(auto it(rbegin(cl::work::list)); it != rend(cl::work::list); ++it)
|
|
|
|
{
|
|
|
|
cl::work *const &other{*it};
|
|
|
|
if(other == work)
|
|
|
|
continue;
|
|
|
|
|
2021-03-17 23:50:38 +01:00
|
|
|
if(!other->handle)
|
|
|
|
continue;
|
|
|
|
|
2021-03-11 18:11:57 +01:00
|
|
|
if(other->context != ctx::current)
|
|
|
|
continue;
|
|
|
|
|
2021-03-13 00:50:27 +01:00
|
|
|
out.at(ret++) = cl_event(other->handle);
|
2021-03-11 18:11:57 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-03-13 00:50:27 +01:00
|
|
|
return vector_view<cl_event>
|
|
|
|
{
|
|
|
|
out, ret
|
|
|
|
};
|
2021-03-11 18:11:57 +01:00
|
|
|
}
|
|
|
|
|
2022-06-21 03:21:17 +02:00
|
|
|
cl_event *
|
|
|
|
ircd::cl::addressof_handle(cl::work *const &work)
|
|
|
|
{
|
|
|
|
const auto handle
|
|
|
|
{
|
|
|
|
std::addressof(work->handle)
|
|
|
|
};
|
|
|
|
|
|
|
|
cl_event *const ret
|
|
|
|
(
|
|
|
|
reinterpret_cast<cl_event *>(handle)
|
|
|
|
);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-01-08 09:53:12 +01:00
|
|
|
//
|
|
|
|
// kern
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::cl::kern::kern(code &code,
|
|
|
|
const string_view &name)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int err {CL_SUCCESS};
|
2021-02-11 10:55:46 +01:00
|
|
|
handle = clCreateKernel(cl_program(code.handle), name.c_str(), &err);
|
2021-01-08 09:53:12 +01:00
|
|
|
throw_on_error(err);
|
2021-04-03 21:25:59 +02:00
|
|
|
|
|
|
|
const std::array<size_t, 3> cgs
|
|
|
|
{
|
|
|
|
#ifdef RB_DEBUG
|
2022-09-30 18:35:11 +02:00
|
|
|
compile_group_size(device[0][0]) //TODO: XXX
|
2021-04-03 21:25:59 +02:00
|
|
|
#else
|
|
|
|
0, 0, 0
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
char buf[1][16];
|
|
|
|
char pbuf[2][48];
|
2022-05-06 02:59:58 +02:00
|
|
|
if constexpr((false))
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "kernel stack %s local %s group:%zu pref:%zu comp:%zu:%zu:%zu :%s",
|
|
|
|
pretty(pbuf[0], iec(stack_mem_size())),
|
|
|
|
pretty(pbuf[1], iec(local_mem_size())),
|
|
|
|
group_size(),
|
|
|
|
preferred_group_size_multiple(),
|
|
|
|
cgs[0], cgs[1], cgs[2],
|
|
|
|
name,
|
|
|
|
};
|
2021-01-08 09:53:12 +01:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "Kernel Create '%s' :%s",
|
|
|
|
name,
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::cl::kern::~kern()
|
|
|
|
noexcept try
|
|
|
|
{
|
2021-03-22 19:06:54 +01:00
|
|
|
if(likely(handle))
|
|
|
|
call(clReleaseKernel, cl_kernel(handle));
|
2021-01-08 09:53:12 +01:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "Kernel Release :%s",
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::cl::kern::arg(const int i,
|
|
|
|
data &data)
|
|
|
|
{
|
2021-02-11 10:55:46 +01:00
|
|
|
const auto &data_handle
|
2021-01-08 09:53:12 +01:00
|
|
|
{
|
2021-02-11 10:55:46 +01:00
|
|
|
cl_mem(data.handle)
|
2021-01-08 09:53:12 +01:00
|
|
|
};
|
|
|
|
|
2021-02-11 10:55:46 +01:00
|
|
|
call(clSetKernelArg, cl_kernel(handle), i, sizeof(cl_mem), &data_handle);
|
2021-01-08 09:53:12 +01:00
|
|
|
}
|
|
|
|
|
2021-03-22 19:05:45 +01:00
|
|
|
void
|
|
|
|
ircd::cl::kern::arg(const int i,
|
|
|
|
const const_buffer &buf)
|
|
|
|
{
|
|
|
|
call(clSetKernelArg, cl_kernel(handle), i, ircd::size(buf), ircd::data(buf));
|
|
|
|
}
|
|
|
|
|
2021-04-03 21:23:52 +02:00
|
|
|
std::array<size_t, 3>
|
|
|
|
ircd::cl::kern::compile_group_size(void *const dev)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
char buf[24];
|
|
|
|
const auto handle(cl_kernel(this->handle));
|
|
|
|
constexpr auto flag(CL_KERNEL_COMPILE_WORK_GROUP_SIZE);
|
|
|
|
return info<std::array<size_t, 3>>(clGetKernelWorkGroupInfo, handle, cl_device_id(dev), flag, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::cl::kern::preferred_group_size_multiple(void *const dev)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
char buf[16];
|
|
|
|
const auto handle(cl_kernel(this->handle));
|
|
|
|
constexpr auto flag(CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE);
|
|
|
|
return info<size_t>(clGetKernelWorkGroupInfo, handle, cl_device_id(dev), flag, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::cl::kern::group_size(void *const dev)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
char buf[16];
|
|
|
|
const auto handle(cl_kernel(this->handle));
|
|
|
|
constexpr auto flag(CL_KERNEL_WORK_GROUP_SIZE);
|
|
|
|
return info<size_t>(clGetKernelWorkGroupInfo, handle, cl_device_id(dev), flag, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::cl::kern::local_mem_size(void *const dev)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
char buf[16];
|
|
|
|
const auto handle(cl_kernel(this->handle));
|
|
|
|
constexpr auto flag(CL_KERNEL_LOCAL_MEM_SIZE);
|
|
|
|
return info<ulong>(clGetKernelWorkGroupInfo, handle, cl_device_id(dev), flag, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::cl::kern::stack_mem_size(void *const dev)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
char buf[16];
|
|
|
|
const auto handle(cl_kernel(this->handle));
|
|
|
|
constexpr auto flag(CL_KERNEL_PRIVATE_MEM_SIZE);
|
|
|
|
return info<ulong>(clGetKernelWorkGroupInfo, handle, cl_device_id(dev), flag, buf);
|
|
|
|
}
|
|
|
|
|
2021-09-22 19:11:22 +02:00
|
|
|
uint
|
|
|
|
ircd::cl::kern::argc()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
const auto handle
|
|
|
|
{
|
|
|
|
cl_kernel(this->handle)
|
|
|
|
};
|
|
|
|
|
|
|
|
char buf[sizeof(uint)];
|
|
|
|
return info<uint>(clGetKernelInfo, handle, CL_KERNEL_NUM_ARGS, buf);
|
|
|
|
}
|
|
|
|
|
2021-10-04 00:32:11 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::cl::kern::name(const mutable_buffer &buf)
|
2021-09-22 19:11:22 +02:00
|
|
|
const
|
|
|
|
{
|
|
|
|
const auto handle
|
|
|
|
{
|
|
|
|
cl_kernel(this->handle)
|
|
|
|
};
|
|
|
|
|
2021-10-04 00:32:11 +02:00
|
|
|
return handle?
|
|
|
|
info(clGetKernelInfo, handle, CL_KERNEL_FUNCTION_NAME, buf):
|
|
|
|
string_view{};
|
2021-09-22 19:11:22 +02:00
|
|
|
}
|
|
|
|
|
2021-01-08 09:53:12 +01:00
|
|
|
//
|
|
|
|
// code
|
|
|
|
//
|
|
|
|
|
2021-10-30 02:49:13 +02:00
|
|
|
namespace ircd::cl
|
|
|
|
{
|
|
|
|
static void build_handle_error_log_line(const string_view &line);
|
|
|
|
static void build_handle_error(code &, const opencl_error &);
|
|
|
|
static void build_handle(cl_program program, void *priv);
|
|
|
|
}
|
|
|
|
|
2022-10-23 21:40:37 +02:00
|
|
|
decltype(ircd::cl::code::iov_max)
|
|
|
|
ircd::cl::code::iov_max
|
|
|
|
{
|
|
|
|
64
|
|
|
|
};
|
|
|
|
|
2021-10-30 02:49:13 +02:00
|
|
|
//
|
|
|
|
// code::code
|
|
|
|
//
|
|
|
|
|
2022-10-23 21:43:38 +02:00
|
|
|
ircd::cl::code::code(path_t,
|
|
|
|
const string_view &paths)
|
|
|
|
:code
|
|
|
|
{
|
|
|
|
path,
|
|
|
|
vector_view<const string_view>(&paths, 1),
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::cl::code::code(path_t,
|
|
|
|
const vector_view<const string_view> &paths_)
|
|
|
|
{
|
|
|
|
static const auto is_cl
|
|
|
|
{
|
|
|
|
[](const auto &path)
|
|
|
|
{
|
|
|
|
return fs::is_reg(path) && fs::is_extension(path, ".cl");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<std::string> buf;
|
|
|
|
for(const auto &path : paths_)
|
|
|
|
if(fs::is_dir(path))
|
|
|
|
{
|
|
|
|
for(const auto &file : fs::ls(path))
|
|
|
|
if(is_cl(file))
|
|
|
|
buf.emplace_back(fs::read(fs::fd(file)));
|
|
|
|
}
|
|
|
|
else if(is_cl(path))
|
|
|
|
buf.emplace_back(fs::read(fs::fd(path)));
|
|
|
|
|
|
|
|
const auto count(buf.size());
|
|
|
|
if(unlikely(count > iov_max))
|
|
|
|
throw error
|
|
|
|
{
|
|
|
|
"Maximum number of sources exceeded: lim:%zu got:%zu",
|
|
|
|
iov_max,
|
|
|
|
count,
|
|
|
|
};
|
|
|
|
|
|
|
|
string_view src[count];
|
|
|
|
for(uint i(0); i < count; ++i)
|
|
|
|
src[i] = buf[i];
|
|
|
|
|
|
|
|
create(vector_view<const string_view>(src, count));
|
|
|
|
}
|
|
|
|
|
2022-01-23 20:56:21 +01:00
|
|
|
ircd::cl::code::code(const string_view &src)
|
2021-01-08 09:53:12 +01:00
|
|
|
:code
|
|
|
|
{
|
2021-03-10 12:03:03 +01:00
|
|
|
vector_view<const string_view>(&src, 1),
|
2021-01-08 09:53:12 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-01-23 20:56:21 +01:00
|
|
|
ircd::cl::code::code(const vector_view<const string_view> &srcs)
|
2021-01-08 09:53:12 +01:00
|
|
|
{
|
2022-10-23 21:40:37 +02:00
|
|
|
create(srcs);
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::cl::code::code(const vector_view<const const_buffer> &bins)
|
|
|
|
{
|
|
|
|
create(bins);
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::cl::code::code(const const_buffer &bc)
|
|
|
|
{
|
|
|
|
char pbuf[1][48];
|
|
|
|
log::logf
|
|
|
|
{
|
|
|
|
log, log::level::DEBUG,
|
|
|
|
"code(%p) loading %s bitcode:%p",
|
|
|
|
this,
|
|
|
|
pretty(pbuf[0], si(ircd::size(bc))),
|
|
|
|
ircd::data(bc),
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(!handle);
|
|
|
|
|
|
|
|
int err {CL_SUCCESS};
|
|
|
|
handle = clCreateProgramWithIL
|
|
|
|
(
|
|
|
|
primary,
|
|
|
|
ircd::data(bc),
|
|
|
|
ircd::size(bc),
|
|
|
|
&err
|
|
|
|
);
|
|
|
|
|
|
|
|
throw_on_error(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::cl::code::~code()
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
if(likely(handle))
|
|
|
|
call(clReleaseProgram, cl_program(handle));
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
2021-01-08 09:53:12 +01:00
|
|
|
{
|
2022-10-23 21:40:37 +02:00
|
|
|
log, "Program Release :%s",
|
|
|
|
e.what(),
|
2021-01-08 09:53:12 +01:00
|
|
|
};
|
|
|
|
|
2022-10-23 21:40:37 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::cl::code::create(const vector_view<const string_view> &srcs)
|
|
|
|
{
|
2022-01-23 20:56:21 +01:00
|
|
|
const auto count(srcs.size());
|
|
|
|
if(unlikely(count > iov_max))
|
2021-01-08 09:53:12 +01:00
|
|
|
throw error
|
|
|
|
{
|
|
|
|
"Maximum number of sources exceeded: lim:%zu got:%zu",
|
|
|
|
iov_max,
|
|
|
|
srcs.size(),
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t len[count];
|
|
|
|
const char *src[count];
|
|
|
|
for(size_t i(0); i < count; ++i)
|
|
|
|
src[i] = ircd::data(srcs[i]),
|
|
|
|
len[i] = ircd::size(srcs[i]);
|
|
|
|
|
2022-01-23 20:56:21 +01:00
|
|
|
char pbuf[1][48];
|
|
|
|
log::logf
|
|
|
|
{
|
|
|
|
log, log::level::DEBUG,
|
|
|
|
"code(%p) creating %s srcs:%zu",
|
|
|
|
this,
|
|
|
|
pretty(pbuf[0], si(std::accumulate(len, len + count, 0))),
|
|
|
|
count,
|
|
|
|
};
|
|
|
|
|
2022-04-24 04:41:10 +02:00
|
|
|
assert(!handle);
|
|
|
|
|
2021-01-08 09:53:12 +01:00
|
|
|
int err {CL_SUCCESS};
|
|
|
|
handle = clCreateProgramWithSource(primary, count, src, len, &err);
|
|
|
|
throw_on_error(err);
|
|
|
|
}
|
|
|
|
|
2022-10-23 21:40:37 +02:00
|
|
|
void
|
|
|
|
ircd::cl::code::create(const vector_view<const const_buffer> &bins)
|
2021-03-22 01:46:31 +01:00
|
|
|
{
|
2022-01-23 20:56:21 +01:00
|
|
|
const auto count(bins.size());
|
|
|
|
if(unlikely(count > iov_max))
|
2021-03-22 01:46:31 +01:00
|
|
|
throw error
|
|
|
|
{
|
|
|
|
"Maximum number of binaries exceeded: lim:%zu got:%zu",
|
|
|
|
iov_max,
|
2022-01-23 20:56:21 +01:00
|
|
|
count,
|
2021-03-22 01:46:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
size_t len[iov_max + 1] {0};
|
|
|
|
const uint8_t *bin[iov_max + 1] {nullptr};
|
|
|
|
for(size_t i(0); i < count; ++i)
|
|
|
|
bin[i] = reinterpret_cast<const uint8_t *>(ircd::data(bins[i])),
|
|
|
|
len[i] = ircd::size(bins[i]);
|
|
|
|
|
|
|
|
size_t devs {0};
|
|
|
|
cl_device_id dev[DEVICE_MAX] {0};
|
|
|
|
for(size_t i(0); i < platforms; ++i)
|
|
|
|
for(size_t j(0); j < devices[i]; ++j)
|
|
|
|
dev[devs++] = device[i][j];
|
|
|
|
|
2022-01-23 20:56:21 +01:00
|
|
|
char pbuf[1][48];
|
|
|
|
log::logf
|
|
|
|
{
|
|
|
|
log, log::level::DEBUG,
|
|
|
|
"code(%p) loading %s bins:%zu devs:%zu",
|
|
|
|
this,
|
|
|
|
pretty(pbuf[0], si(std::accumulate(len, len + count, 0))),
|
|
|
|
count,
|
|
|
|
devs,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(len);
|
|
|
|
assert(devs);
|
2022-04-24 04:41:10 +02:00
|
|
|
assert(!handle);
|
2022-01-23 20:56:21 +01:00
|
|
|
|
2021-03-22 01:46:31 +01:00
|
|
|
int err {CL_SUCCESS};
|
|
|
|
int binerr[iov_max + 1] {CL_SUCCESS};
|
|
|
|
handle = clCreateProgramWithBinary(primary, devs, dev, len, bin, binerr, &err);
|
|
|
|
throw_on_error(err);
|
|
|
|
for(size_t i(0); i < count; ++i)
|
|
|
|
throw_on_error(binerr[i]);
|
|
|
|
}
|
|
|
|
|
2021-01-08 09:53:12 +01:00
|
|
|
void
|
|
|
|
ircd::cl::code::build(const string_view &opts)
|
|
|
|
try
|
|
|
|
{
|
2022-01-23 20:56:21 +01:00
|
|
|
const uint num_devices {1};
|
|
|
|
const cl_device_id *device_list
|
2021-10-30 02:49:13 +02:00
|
|
|
{
|
2022-01-23 20:56:21 +01:00
|
|
|
device[0] //TODO: XXX
|
2021-10-30 02:49:13 +02:00
|
|
|
};
|
|
|
|
|
2022-01-23 20:56:21 +01:00
|
|
|
log::logf
|
2021-10-30 02:49:13 +02:00
|
|
|
{
|
2022-01-23 20:56:21 +01:00
|
|
|
log, log::level::DEBUG,
|
|
|
|
"code(%p) building devs:%zu %c%s",
|
|
|
|
this,
|
|
|
|
num_devices,
|
|
|
|
opts? ':': ' ',
|
|
|
|
opts,
|
2021-10-30 02:49:13 +02:00
|
|
|
};
|
|
|
|
|
2021-01-08 09:53:12 +01:00
|
|
|
call
|
|
|
|
(
|
|
|
|
clBuildProgram,
|
2021-02-11 10:55:46 +01:00
|
|
|
cl_program(handle),
|
2021-01-08 09:53:12 +01:00
|
|
|
num_devices,
|
|
|
|
device_list,
|
|
|
|
opts.c_str(),
|
2021-03-19 18:11:10 +01:00
|
|
|
cl::build_handle,
|
2021-10-30 02:49:13 +02:00
|
|
|
this
|
2021-01-08 09:53:12 +01:00
|
|
|
);
|
|
|
|
}
|
2021-03-19 18:11:10 +01:00
|
|
|
catch(const opencl_error &e)
|
|
|
|
{
|
|
|
|
build_handle_error(*this, e);
|
|
|
|
throw;
|
|
|
|
}
|
2021-01-08 09:53:12 +01:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2021-03-19 18:11:10 +01:00
|
|
|
log::error
|
2021-01-08 09:53:12 +01:00
|
|
|
{
|
2021-03-19 18:11:10 +01:00
|
|
|
log, "code(%p) :Failed to build :%s",
|
|
|
|
this,
|
|
|
|
e.what(),
|
|
|
|
};
|
2021-01-08 09:53:12 +01:00
|
|
|
|
2021-03-19 18:11:10 +01:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2022-01-23 20:56:21 +01:00
|
|
|
void
|
|
|
|
ircd::cl::code::link(const string_view &opts)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const uint num_devices {1};
|
|
|
|
const cl_device_id *device_list
|
|
|
|
{
|
|
|
|
device[0] //TODO: XXX
|
|
|
|
};
|
|
|
|
|
2022-04-25 03:54:40 +02:00
|
|
|
assert(this->handle);
|
2022-01-23 20:56:21 +01:00
|
|
|
const uint num_progs {1};
|
|
|
|
const cl_program progs[]
|
|
|
|
{
|
2022-04-25 03:54:40 +02:00
|
|
|
cl_program(this->handle)
|
2022-01-23 20:56:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
log::logf
|
|
|
|
{
|
|
|
|
log, log::level::DEBUG,
|
2022-05-09 03:20:45 +02:00
|
|
|
"code(%p) linking devs:%zu progs:%zu opts:%zu$B %c%s",
|
2022-01-23 20:56:21 +01:00
|
|
|
this,
|
|
|
|
num_devices,
|
|
|
|
num_progs,
|
2022-05-09 03:20:45 +02:00
|
|
|
ircd::size(opts),
|
2022-01-23 20:56:21 +01:00
|
|
|
opts? ':': ' ',
|
|
|
|
opts,
|
|
|
|
};
|
|
|
|
|
|
|
|
int err
|
|
|
|
{
|
|
|
|
CL_COMPILER_NOT_AVAILABLE
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CL_VERSION_1_2
|
2022-04-25 03:54:40 +02:00
|
|
|
void *handle
|
|
|
|
{
|
|
|
|
clLinkProgram
|
|
|
|
(
|
|
|
|
primary,
|
|
|
|
num_devices,
|
|
|
|
device_list,
|
|
|
|
opts.c_str(),
|
|
|
|
num_progs,
|
|
|
|
progs,
|
|
|
|
cl::build_handle,
|
|
|
|
this,
|
|
|
|
&err
|
|
|
|
)
|
|
|
|
};
|
2022-05-09 03:20:45 +02:00
|
|
|
#endif
|
2022-01-23 20:56:21 +01:00
|
|
|
|
|
|
|
throw_on_error(err);
|
2022-04-25 03:54:40 +02:00
|
|
|
std::swap(handle, this->handle);
|
|
|
|
call(clReleaseProgram, cl_program(handle));
|
2022-01-23 20:56:21 +01:00
|
|
|
}
|
|
|
|
catch(const opencl_error &e)
|
|
|
|
{
|
|
|
|
build_handle_error(*this, e);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "code(%p) :Failed to link :%s",
|
|
|
|
this,
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::cl::code::compile(const string_view &opts)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const uint num_devices {1};
|
|
|
|
const cl_device_id *device_list
|
|
|
|
{
|
|
|
|
device[0] //TODO: XXX
|
|
|
|
};
|
|
|
|
|
|
|
|
const uint num_headers {0};
|
|
|
|
const cl_program *header_progs
|
|
|
|
{
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *header_names[]
|
|
|
|
{
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
|
|
|
log::logf
|
|
|
|
{
|
|
|
|
log, log::level::DEBUG,
|
|
|
|
"code(%p) compiling devs:%zu headers:%zu %c%s",
|
|
|
|
this,
|
|
|
|
num_devices,
|
|
|
|
num_headers,
|
|
|
|
opts? ':': ' ',
|
|
|
|
opts,
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CL_VERSION_1_2
|
|
|
|
call
|
|
|
|
(
|
|
|
|
clCompileProgram,
|
|
|
|
cl_program(handle),
|
|
|
|
num_devices,
|
|
|
|
device_list,
|
|
|
|
opts.c_str(),
|
|
|
|
num_headers,
|
|
|
|
header_progs,
|
|
|
|
nullptr, //header_names, // clover api bug?
|
|
|
|
cl::build_handle,
|
|
|
|
this
|
|
|
|
);
|
|
|
|
#else
|
|
|
|
throw_on_error(CL_COMPILER_NOT_AVAILABLE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
catch(const opencl_error &e)
|
|
|
|
{
|
|
|
|
build_handle_error(*this, e);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "code(%p) :Failed to compile :%s",
|
|
|
|
this,
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2021-10-30 02:49:13 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::cl::code::src(const mutable_buffer &buf)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
const auto &handle
|
|
|
|
{
|
|
|
|
cl_program(this->handle)
|
|
|
|
};
|
|
|
|
|
|
|
|
return info(clGetProgramInfo, handle, CL_PROGRAM_SOURCE, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::vector_view<const ircd::mutable_buffer>
|
|
|
|
ircd::cl::code::bin(vector_view<mutable_buffer> buf)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
const auto &handle
|
|
|
|
{
|
|
|
|
cl_program(this->handle)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto devs
|
|
|
|
{
|
|
|
|
this->devs()
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(devs <= ircd::size(buf));
|
|
|
|
const auto count
|
|
|
|
{
|
|
|
|
std::min(devs, ircd::size(buf))
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t bin_sz[count];
|
|
|
|
const auto bins
|
|
|
|
{
|
|
|
|
this->bins({bin_sz, count})
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(bins <= count);
|
|
|
|
const auto num
|
|
|
|
{
|
|
|
|
std::min(bins, count)
|
|
|
|
};
|
|
|
|
|
|
|
|
for(size_t i(0); i < num; ++i)
|
|
|
|
buf[i] = mutable_buffer
|
|
|
|
{
|
|
|
|
buf[i], bin_sz[i]
|
|
|
|
};
|
|
|
|
|
|
|
|
uintptr_t ptr[num];
|
|
|
|
for(size_t i(0); i < num; ++i)
|
|
|
|
ptr[i] = uintptr_t(ircd::data(buf[i]));
|
|
|
|
|
|
|
|
info(clGetProgramInfo, handle, CL_PROGRAM_BINARIES, mutable_buffer
|
|
|
|
{
|
|
|
|
reinterpret_cast<char *>(ptr), sizeof(uintptr_t) * num
|
|
|
|
});
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::cl::code::bins_size()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
const auto devs
|
|
|
|
{
|
|
|
|
this->devs()
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t bin_sz[devs];
|
|
|
|
const auto bins
|
|
|
|
{
|
|
|
|
this->bins({bin_sz, devs})
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(bins <= devs);
|
|
|
|
const auto ret
|
|
|
|
{
|
|
|
|
std::accumulate(bin_sz, bin_sz + bins, 0UL)
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::cl::code::bins(const vector_view<size_t> &buf)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
const auto &handle
|
|
|
|
{
|
|
|
|
cl_program(this->handle)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto count
|
|
|
|
{
|
|
|
|
devs()
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(count <= size(buf));
|
|
|
|
info(clGetProgramInfo, handle, CL_PROGRAM_BINARY_SIZES, mutable_buffer
|
|
|
|
{
|
|
|
|
reinterpret_cast<char *>(ircd::data(buf)), ircd::size(buf) * sizeof(size_t)
|
|
|
|
});
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::cl::code::devs()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
char buf[sizeof(uint)];
|
|
|
|
const auto &handle
|
|
|
|
{
|
|
|
|
cl_program(this->handle)
|
|
|
|
};
|
|
|
|
|
|
|
|
return info<uint>(clGetProgramInfo, handle, CL_PROGRAM_NUM_DEVICES, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
long
|
|
|
|
ircd::cl::code::status()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
const auto &handle
|
|
|
|
{
|
|
|
|
cl_program(this->handle)
|
|
|
|
};
|
|
|
|
|
|
|
|
cl_build_status buf;
|
|
|
|
const mutable_buffer mb
|
|
|
|
{
|
|
|
|
reinterpret_cast<char *>(&buf), sizeof(buf)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto &dev
|
|
|
|
{
|
|
|
|
device[0][0], //TODO: XXX
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto ret
|
|
|
|
{
|
|
|
|
info<cl_build_status>(clGetProgramBuildInfo, handle, dev, CL_PROGRAM_BUILD_STATUS, mb)
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-03-19 18:11:10 +01:00
|
|
|
void
|
|
|
|
ircd::cl::build_handle(cl_program program,
|
|
|
|
void *const priv)
|
|
|
|
{
|
2021-10-30 02:49:13 +02:00
|
|
|
cl::code *const &code
|
2021-09-01 20:28:40 +02:00
|
|
|
{
|
2021-10-30 02:49:13 +02:00
|
|
|
reinterpret_cast<cl::code *>(priv)
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(code);
|
|
|
|
char pbuf[1][48];
|
|
|
|
log::logf
|
|
|
|
{
|
|
|
|
log, log::level::DEBUG,
|
|
|
|
"program(%p) devs:%zu binsz:%s :Build complete.",
|
2021-09-01 20:28:40 +02:00
|
|
|
(const void *)program,
|
2021-10-30 02:49:13 +02:00
|
|
|
code->devs(),
|
|
|
|
pretty(pbuf[0], si(code->bins_size())),
|
2021-09-01 20:28:40 +02:00
|
|
|
};
|
2021-03-19 18:11:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::cl::build_handle_error(code &code,
|
|
|
|
const opencl_error &e)
|
|
|
|
{
|
|
|
|
const auto string_closure
|
|
|
|
{
|
|
|
|
[&code](const mutable_buffer &buf)
|
|
|
|
{
|
|
|
|
size_t len {0}; call
|
|
|
|
(
|
|
|
|
clGetProgramBuildInfo,
|
|
|
|
cl_program(code.handle),
|
2021-10-30 02:49:13 +02:00
|
|
|
device[0][0], //TODO: XXX
|
2021-03-19 18:11:10 +01:00
|
|
|
CL_PROGRAM_BUILD_LOG,
|
|
|
|
ircd::size(buf),
|
|
|
|
ircd::data(buf),
|
|
|
|
&len
|
|
|
|
);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
};
|
2021-01-08 09:53:12 +01:00
|
|
|
|
|
|
|
const auto error_message
|
|
|
|
{
|
2021-03-19 18:11:10 +01:00
|
|
|
ircd::string(8_KiB | SHRINK_TO_FIT, string_closure)
|
2021-01-08 09:53:12 +01:00
|
|
|
};
|
|
|
|
|
2021-03-19 18:11:10 +01:00
|
|
|
const auto lines
|
2021-01-08 09:53:12 +01:00
|
|
|
{
|
2021-03-19 18:11:10 +01:00
|
|
|
ircd::tokens(error_message, '\n', build_handle_error_log_line)
|
|
|
|
};
|
|
|
|
}
|
2021-01-08 09:53:12 +01:00
|
|
|
|
2021-03-19 18:11:10 +01:00
|
|
|
void
|
|
|
|
ircd::cl::build_handle_error_log_line(const string_view &line)
|
|
|
|
{
|
|
|
|
// note last line is just a CR
|
|
|
|
if(line.size() <= 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto &[loc, line_] { split(line, ' ') };
|
|
|
|
const auto &[fac, msg] { split(line_, ' ') };
|
|
|
|
const auto &[fname, pos] { split(loc, ':') };
|
|
|
|
const auto &[row, col] { split(pos, ':') };
|
|
|
|
|
|
|
|
const auto level
|
|
|
|
{
|
|
|
|
startswith(fac, "warning")?
|
|
|
|
log::level::WARNING:
|
|
|
|
|
|
|
|
startswith(fac, "error")?
|
|
|
|
log::level::ERROR:
|
|
|
|
|
|
|
|
log::level::ERROR
|
|
|
|
};
|
|
|
|
|
|
|
|
log::logf
|
|
|
|
{
|
|
|
|
log, level, "%s", line
|
|
|
|
};
|
2021-01-08 09:53:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// data
|
|
|
|
//
|
|
|
|
|
2022-03-05 21:43:43 +01:00
|
|
|
decltype(ircd::cl::data::gart_page_size)
|
|
|
|
ircd::cl::data::gart_page_size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.cl.data.gart.page_size" },
|
|
|
|
{ "default", 4096 },
|
|
|
|
{ "help", "Override (un)detected gart page size." },
|
|
|
|
};
|
2021-03-14 23:21:05 +01:00
|
|
|
|
2022-03-05 21:43:43 +01:00
|
|
|
ircd::cl::data::data(const size_t size,
|
|
|
|
const bool host_read,
|
|
|
|
const bool host_write)
|
|
|
|
{
|
2021-04-15 05:56:01 +02:00
|
|
|
if(!size)
|
|
|
|
return;
|
|
|
|
|
2021-01-08 09:53:12 +01:00
|
|
|
cl_mem_flags flags {0};
|
2022-03-05 21:43:43 +01:00
|
|
|
flags |= CL_MEM_READ_WRITE;
|
|
|
|
flags |= host_read && !host_write? CL_MEM_HOST_READ_ONLY: 0;
|
|
|
|
flags |= !host_read && host_write? CL_MEM_HOST_WRITE_ONLY: 0;
|
|
|
|
flags |= !host_read && !host_write? CL_MEM_HOST_NO_ACCESS: 0;
|
2021-03-14 23:21:05 +01:00
|
|
|
|
2022-09-30 19:20:35 +02:00
|
|
|
char pbuf[48];
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "data(%p) device %s %lu@ host[read:%b write:%b] flags:%08x",
|
|
|
|
this,
|
|
|
|
pretty(pbuf, iec(size)),
|
|
|
|
alignment(size),
|
|
|
|
host_read,
|
|
|
|
host_write,
|
|
|
|
flags,
|
|
|
|
};
|
|
|
|
|
2021-03-14 23:21:05 +01:00
|
|
|
int err {CL_SUCCESS};
|
2022-03-05 21:43:43 +01:00
|
|
|
handle = clCreateBuffer
|
|
|
|
(
|
|
|
|
primary,
|
|
|
|
flags,
|
|
|
|
size,
|
|
|
|
nullptr,
|
|
|
|
&err
|
|
|
|
);
|
2021-03-26 02:36:36 +01:00
|
|
|
|
2022-03-05 21:43:43 +01:00
|
|
|
throw_on_error(err);
|
2021-03-26 02:36:36 +01:00
|
|
|
primary_stats.alloc_count += 1;
|
|
|
|
primary_stats.alloc_bytes += size;
|
2021-03-14 23:21:05 +01:00
|
|
|
}
|
|
|
|
|
2022-03-05 21:43:43 +01:00
|
|
|
ircd::cl::data::data(const mutable_buffer &buf,
|
|
|
|
const bool wonly)
|
2021-03-14 23:21:05 +01:00
|
|
|
{
|
2021-04-15 05:56:01 +02:00
|
|
|
const auto &ptr
|
2021-03-14 23:21:05 +01:00
|
|
|
{
|
2022-03-05 21:43:43 +01:00
|
|
|
ircd::data(buf)
|
2021-03-14 23:21:05 +01:00
|
|
|
};
|
|
|
|
|
2021-04-15 05:56:01 +02:00
|
|
|
const auto &size
|
2021-03-14 23:21:05 +01:00
|
|
|
{
|
2022-03-19 23:13:40 +01:00
|
|
|
ircd::size(buf)
|
2021-03-14 23:21:05 +01:00
|
|
|
};
|
|
|
|
|
2021-04-15 05:56:01 +02:00
|
|
|
if(!size)
|
|
|
|
return;
|
|
|
|
|
2021-03-14 23:21:05 +01:00
|
|
|
cl_mem_flags flags {0};
|
2022-03-19 23:13:40 +01:00
|
|
|
flags |= CL_MEM_USE_HOST_PTR;
|
2022-03-05 21:43:43 +01:00
|
|
|
flags |= wonly? CL_MEM_WRITE_ONLY: CL_MEM_READ_WRITE;
|
|
|
|
|
2022-09-30 19:20:35 +02:00
|
|
|
char pbuf[48];
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "data(%p) mutable %p %lu@ %s %lu@ wonly:%b flags:%08x",
|
|
|
|
this,
|
|
|
|
ptr,
|
|
|
|
alignment(ptr),
|
|
|
|
pretty(pbuf, iec(size)),
|
|
|
|
alignment(size),
|
|
|
|
wonly,
|
|
|
|
flags,
|
|
|
|
};
|
|
|
|
|
2022-03-05 21:43:43 +01:00
|
|
|
assert(!ptr || aligned(buf, size_t(gart_page_size)));
|
|
|
|
assert(padded(size, size_t(gart_page_size)));
|
2021-03-14 23:21:05 +01:00
|
|
|
|
|
|
|
int err {CL_SUCCESS};
|
2022-03-05 21:43:43 +01:00
|
|
|
handle = clCreateBuffer
|
|
|
|
(
|
|
|
|
primary,
|
|
|
|
flags,
|
|
|
|
size,
|
2022-03-19 23:13:40 +01:00
|
|
|
ptr,
|
2022-03-05 21:43:43 +01:00
|
|
|
&err
|
|
|
|
);
|
2021-03-26 02:36:36 +01:00
|
|
|
|
2022-03-05 21:43:43 +01:00
|
|
|
throw_on_error(err);
|
2021-03-26 02:36:36 +01:00
|
|
|
primary_stats.alloc_count += 1;
|
|
|
|
primary_stats.alloc_bytes += size;
|
2021-01-08 09:53:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::cl::data::data(const const_buffer &buf)
|
|
|
|
{
|
2021-04-15 05:56:01 +02:00
|
|
|
const auto &ptr
|
|
|
|
{
|
2022-03-05 21:43:43 +01:00
|
|
|
ircd::data(buf)
|
2021-04-15 05:56:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const auto &size
|
|
|
|
{
|
2022-03-19 23:13:40 +01:00
|
|
|
ircd::size(buf)
|
2021-04-15 05:56:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if(!size)
|
|
|
|
return;
|
|
|
|
|
2021-01-08 09:53:12 +01:00
|
|
|
cl_mem_flags flags {0};
|
2022-03-19 23:13:40 +01:00
|
|
|
flags |= CL_MEM_USE_HOST_PTR;
|
2021-01-08 09:53:12 +01:00
|
|
|
flags |= CL_MEM_READ_ONLY;
|
2022-03-05 21:43:43 +01:00
|
|
|
|
2022-09-30 19:20:35 +02:00
|
|
|
char pbuf[48];
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "data(%p) immutable %p %lu@ %s %lu@ flags:%08x",
|
|
|
|
this,
|
|
|
|
ptr,
|
|
|
|
alignment(ptr),
|
|
|
|
pretty(pbuf, iec(size)),
|
|
|
|
alignment(size),
|
|
|
|
flags,
|
|
|
|
};
|
|
|
|
|
2022-03-05 21:43:43 +01:00
|
|
|
assert(!ptr || aligned(buf, size_t(gart_page_size)));
|
|
|
|
assert(padded(size, size_t(gart_page_size)));
|
2021-03-14 23:21:05 +01:00
|
|
|
|
|
|
|
int err {CL_SUCCESS};
|
2022-03-05 21:43:43 +01:00
|
|
|
handle = clCreateBuffer
|
|
|
|
(
|
|
|
|
primary,
|
|
|
|
flags,
|
|
|
|
size,
|
2022-03-19 23:13:40 +01:00
|
|
|
mutable_cast(ptr),
|
2022-03-05 21:43:43 +01:00
|
|
|
&err
|
|
|
|
);
|
|
|
|
|
2021-01-08 09:53:12 +01:00
|
|
|
throw_on_error(err);
|
2022-03-05 21:43:43 +01:00
|
|
|
primary_stats.alloc_count += 1;
|
|
|
|
primary_stats.alloc_bytes += size;
|
2021-01-08 09:53:12 +01:00
|
|
|
}
|
|
|
|
|
2021-03-29 21:56:45 +02:00
|
|
|
ircd::cl::data::data(data &master,
|
|
|
|
const pair<size_t, off_t> &slice)
|
|
|
|
{
|
2022-03-05 21:43:43 +01:00
|
|
|
constexpr auto type
|
|
|
|
{
|
|
|
|
CL_BUFFER_CREATE_TYPE_REGION
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!master.handle)
|
|
|
|
return;
|
2021-03-29 21:56:45 +02:00
|
|
|
|
|
|
|
cl_buffer_region region {0};
|
|
|
|
region.size = slice.first;
|
2022-05-06 01:24:26 +02:00
|
|
|
region.origin = master.offset() + slice.second;
|
|
|
|
|
2021-09-16 06:19:36 +02:00
|
|
|
if(!region.size)
|
|
|
|
return;
|
|
|
|
|
2022-05-06 01:24:26 +02:00
|
|
|
const auto root
|
|
|
|
{
|
|
|
|
master.master()?: master.handle
|
|
|
|
};
|
|
|
|
|
2022-09-30 19:20:35 +02:00
|
|
|
char pbuf[48];
|
|
|
|
if constexpr((false))
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "data(%p) master(%p) region offset:%zu %lu@ %s %lu@",
|
|
|
|
this,
|
|
|
|
root,
|
|
|
|
region.origin,
|
|
|
|
alignment(region.origin),
|
|
|
|
pretty(pbuf, iec(region.size)),
|
|
|
|
alignment(region.size),
|
|
|
|
};
|
|
|
|
|
2022-03-05 21:43:43 +01:00
|
|
|
assert(aligned(region.origin, size_t(gart_page_size)));
|
|
|
|
assert(padded(region.size, size_t(gart_page_size)));
|
2022-05-06 01:24:26 +02:00
|
|
|
assert(root);
|
2022-03-05 21:43:43 +01:00
|
|
|
|
2021-03-29 21:56:45 +02:00
|
|
|
int err {CL_SUCCESS};
|
2022-03-05 21:43:43 +01:00
|
|
|
handle = clCreateSubBuffer
|
|
|
|
(
|
2022-05-06 01:24:26 +02:00
|
|
|
cl_mem(root),
|
2022-03-05 21:43:43 +01:00
|
|
|
cl_mem_flags{0},
|
|
|
|
type,
|
|
|
|
®ion,
|
|
|
|
&err
|
|
|
|
);
|
|
|
|
|
2021-03-29 21:56:45 +02:00
|
|
|
throw_on_error(err);
|
|
|
|
}
|
|
|
|
|
2021-01-08 09:53:12 +01:00
|
|
|
ircd::cl::data::~data()
|
|
|
|
noexcept try
|
|
|
|
{
|
2022-03-21 23:18:08 +01:00
|
|
|
assert(handle || !mapped);
|
|
|
|
|
2021-03-22 19:06:54 +01:00
|
|
|
if(likely(handle))
|
2021-03-26 02:36:36 +01:00
|
|
|
{
|
|
|
|
const auto size
|
|
|
|
{
|
|
|
|
this->size()
|
|
|
|
};
|
|
|
|
|
2021-03-22 19:06:54 +01:00
|
|
|
call(clReleaseMemObject, cl_mem(handle));
|
2021-03-26 02:36:36 +01:00
|
|
|
|
|
|
|
primary_stats.dealloc_count += 1;
|
|
|
|
primary_stats.dealloc_bytes += size;
|
|
|
|
}
|
2021-01-08 09:53:12 +01:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "Memory Release :%s",
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-18 01:12:58 +01:00
|
|
|
char *
|
|
|
|
ircd::cl::data::ptr()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
assert(handle);
|
|
|
|
|
|
|
|
char buf[sizeof(void *)] {0};
|
2022-03-19 23:15:23 +01:00
|
|
|
const auto ret
|
|
|
|
{
|
|
|
|
this->mapped?
|
|
|
|
static_cast<char *>(this->mapped):
|
|
|
|
info<char *>(clGetMemObjectInfo, cl_mem(mutable_cast(handle)), CL_MEM_HOST_PTR, buf)
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::cl::data::refs()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
assert(handle);
|
|
|
|
|
|
|
|
char buf[sizeof(size_t)] {0};
|
|
|
|
return info<uint>(clGetMemObjectInfo, cl_mem(mutable_cast(handle)), CL_MEM_REFERENCE_COUNT, buf);
|
2021-03-18 01:12:58 +01:00
|
|
|
}
|
|
|
|
|
2021-09-15 13:32:38 +02:00
|
|
|
off_t
|
|
|
|
ircd::cl::data::offset()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
assert(handle);
|
|
|
|
|
|
|
|
char buf[sizeof(off_t)] {0};
|
|
|
|
return info<off_t>(clGetMemObjectInfo, cl_mem(mutable_cast(handle)), CL_MEM_OFFSET, buf);
|
|
|
|
}
|
|
|
|
|
2021-03-18 01:12:58 +01:00
|
|
|
size_t
|
|
|
|
ircd::cl::data::size()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
assert(handle);
|
|
|
|
|
|
|
|
char buf[sizeof(size_t)] {0};
|
|
|
|
return info<size_t>(clGetMemObjectInfo, cl_mem(mutable_cast(handle)), CL_MEM_SIZE, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint
|
|
|
|
ircd::cl::data::flags()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
assert(handle);
|
|
|
|
|
|
|
|
char buf[sizeof(uint)] {0};
|
|
|
|
return info<uint>(clGetMemObjectInfo, cl_mem(mutable_cast(handle)), CL_MEM_FLAGS, buf);
|
|
|
|
}
|
|
|
|
|
2022-05-06 01:24:01 +02:00
|
|
|
void *
|
|
|
|
ircd::cl::data::master()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
assert(handle);
|
|
|
|
|
|
|
|
char buf[sizeof(void *)] {0};
|
|
|
|
constexpr auto qtype(CL_MEM_ASSOCIATED_MEMOBJECT);
|
|
|
|
return info<cl_mem>(clGetMemObjectInfo, cl_mem(mutable_cast(handle)), qtype, buf);
|
|
|
|
}
|
|
|
|
|
2021-01-08 09:53:12 +01:00
|
|
|
//
|
|
|
|
// cl::work (event)
|
|
|
|
//
|
|
|
|
|
|
|
|
namespace ircd::cl
|
|
|
|
{
|
2021-03-18 01:56:01 +01:00
|
|
|
struct completion;
|
2021-01-08 09:53:12 +01:00
|
|
|
|
2021-04-10 00:56:42 +02:00
|
|
|
extern conf::item<bool> offload_enable;
|
|
|
|
extern const ctx::ole::opts offload_opts;
|
|
|
|
|
|
|
|
static void handle_event_callback(cl_event, cl_int, void *) noexcept;
|
|
|
|
static int wait_event_callback(work &, const int, const int);
|
|
|
|
static int wait_event_offload(work &, const int, const int);
|
|
|
|
static int wait_event(work &, const int, const int);
|
2021-03-11 18:11:57 +01:00
|
|
|
}
|
|
|
|
|
2021-04-10 00:56:42 +02:00
|
|
|
struct alignas(64) ircd::cl::completion
|
2021-03-18 01:56:01 +01:00
|
|
|
{
|
|
|
|
cl_event event {nullptr};
|
|
|
|
cl_int status {CL_COMPLETE};
|
|
|
|
ctx::dock dock;
|
|
|
|
};
|
|
|
|
|
2021-04-10 00:56:42 +02:00
|
|
|
decltype(ircd::cl::offload_enable)
|
|
|
|
ircd::cl::offload_enable
|
|
|
|
{
|
|
|
|
{ "name", "ircd.cl.offload.enable" },
|
|
|
|
{ "default", true },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::cl::offload_opts)
|
|
|
|
ircd::cl::offload_opts
|
|
|
|
{
|
|
|
|
"cl"
|
|
|
|
};
|
|
|
|
|
2022-06-14 23:15:53 +02:00
|
|
|
[[gnu::visibility("hidden")]]
|
2021-03-11 18:11:57 +01:00
|
|
|
void
|
|
|
|
ircd::cl::work::init()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-06-14 23:15:53 +02:00
|
|
|
[[using gnu: cold, visibility("hidden")]]
|
2021-03-11 18:11:57 +01:00
|
|
|
void
|
|
|
|
ircd::cl::work::fini()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
cl::sync();
|
|
|
|
}
|
|
|
|
|
2021-03-20 22:33:40 +01:00
|
|
|
//
|
|
|
|
// work::work
|
|
|
|
//
|
2021-03-11 18:11:57 +01:00
|
|
|
|
2021-03-20 22:33:40 +01:00
|
|
|
ircd::cl::work::work()
|
2021-03-11 18:11:57 +01:00
|
|
|
{
|
2021-10-28 00:22:40 +02:00
|
|
|
if(unlikely(!cl::linkage))
|
2021-10-15 20:38:47 +02:00
|
|
|
throw unavailable
|
|
|
|
{
|
2021-10-28 00:22:40 +02:00
|
|
|
"OpenCL runtime is not available."
|
2021-10-15 20:38:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
assert(cl::linkage);
|
2021-01-08 09:53:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::cl::work::work(void *const &handle)
|
|
|
|
{
|
|
|
|
call(clRetainEvent, cl_event(handle));
|
|
|
|
this->handle = handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::cl::work::~work()
|
|
|
|
noexcept try
|
|
|
|
{
|
2021-03-20 22:33:40 +01:00
|
|
|
if(!handle)
|
|
|
|
return;
|
|
|
|
|
2021-03-18 19:15:49 +01:00
|
|
|
const unwind free{[this]
|
|
|
|
{
|
2021-03-20 22:33:40 +01:00
|
|
|
assert(handle);
|
|
|
|
call(clReleaseEvent, cl_event(handle));
|
2021-03-18 19:15:49 +01:00
|
|
|
}};
|
|
|
|
|
2021-03-17 23:50:38 +01:00
|
|
|
wait();
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
2021-01-08 09:53:12 +01:00
|
|
|
{
|
2021-03-17 23:50:38 +01:00
|
|
|
log, "Work Release :%s",
|
|
|
|
e.what(),
|
2021-01-08 09:53:12 +01:00
|
|
|
};
|
|
|
|
|
2021-03-17 23:50:38 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-20 22:33:40 +01:00
|
|
|
void
|
|
|
|
ircd::cl::work::wait(const uint desired)
|
2021-03-18 21:21:10 +01:00
|
|
|
try
|
2021-03-17 23:50:38 +01:00
|
|
|
{
|
2021-03-20 22:33:40 +01:00
|
|
|
static_assert(CL_COMPLETE == 0);
|
2022-03-05 21:44:06 +01:00
|
|
|
constexpr auto execution_status
|
2021-01-08 09:53:12 +01:00
|
|
|
{
|
2022-03-05 21:44:06 +01:00
|
|
|
CL_EVENT_COMMAND_EXECUTION_STATUS
|
2021-03-11 18:11:57 +01:00
|
|
|
};
|
2021-01-08 09:53:12 +01:00
|
|
|
|
2022-03-05 21:44:06 +01:00
|
|
|
char buf[4];
|
|
|
|
int status {0};
|
|
|
|
if(likely(handle))
|
|
|
|
status = info<int>(clGetEventInfo, cl_event(handle), execution_status, buf);
|
|
|
|
|
2021-03-20 22:33:40 +01:00
|
|
|
if(status > int(desired))
|
2021-04-10 00:56:42 +02:00
|
|
|
status = wait_event(*this, status, desired);
|
2021-01-08 09:53:12 +01:00
|
|
|
|
2021-03-18 21:21:10 +01:00
|
|
|
if(unlikely(status < 0))
|
|
|
|
throw_on_error(status);
|
|
|
|
|
2021-03-20 22:33:40 +01:00
|
|
|
assert(int(status) == int(desired));
|
2021-01-08 09:53:12 +01:00
|
|
|
}
|
2021-03-18 21:21:10 +01:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
2021-03-20 22:33:40 +01:00
|
|
|
log, "work(%p)::wait(%u) :%s",
|
2021-03-18 21:21:10 +01:00
|
|
|
this,
|
2021-03-20 22:33:40 +01:00
|
|
|
desired,
|
2021-03-18 21:21:10 +01:00
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
2021-01-08 09:53:12 +01:00
|
|
|
|
2021-10-04 00:32:11 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::cl::work::name(const mutable_buffer &buf)
|
2021-09-22 19:11:22 +02:00
|
|
|
const
|
|
|
|
{
|
|
|
|
switch(const auto type(this->type()); type)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
return nullptr;
|
|
|
|
|
2022-03-05 21:46:36 +01:00
|
|
|
case CL_COMMAND_READ_BUFFER: return "READ_BUFFER";
|
|
|
|
case CL_COMMAND_WRITE_BUFFER: return "WRITE_BUFFER";
|
|
|
|
case CL_COMMAND_COPY_BUFFER: return "COPY_BUFFER";
|
|
|
|
case CL_COMMAND_MAP_BUFFER: return "MAP_BUFFER";
|
|
|
|
case CL_COMMAND_UNMAP_MEM_OBJECT: return "UNMAP_MEM_OBJECT";
|
2021-09-22 19:11:22 +02:00
|
|
|
case CL_COMMAND_NDRANGE_KERNEL:
|
|
|
|
{
|
|
|
|
const auto kern
|
|
|
|
{
|
|
|
|
reinterpret_cast<const cl::kern *>(object)
|
|
|
|
};
|
|
|
|
|
2022-03-05 21:46:36 +01:00
|
|
|
return kern? kern->name(buf): "NDRANGE_KERNEL";
|
2021-09-22 19:11:22 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ircd::cl::work::type()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
const auto handle
|
|
|
|
{
|
|
|
|
cl_event(this->handle)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!handle)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
char buf[4];
|
|
|
|
return info<int>(clGetEventInfo, handle, CL_EVENT_COMMAND_TYPE, buf);
|
|
|
|
}
|
|
|
|
|
2021-10-04 00:31:04 +02:00
|
|
|
//
|
|
|
|
// cl::work::prof
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::cl::work::prof::prof(const cl::work &w)
|
|
|
|
{
|
|
|
|
const auto h
|
|
|
|
{
|
|
|
|
cl_event(w.handle)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!profile_queue || !h)
|
|
|
|
{
|
|
|
|
for(uint i(0); i < this->size(); ++i)
|
|
|
|
(*this)[i] = 0ns;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char b[5][8];
|
|
|
|
(*this)[0] = info<nanoseconds>(clGetEventProfilingInfo, h, CL_PROFILING_COMMAND_QUEUED, b[0]);
|
|
|
|
(*this)[1] = info<nanoseconds>(clGetEventProfilingInfo, h, CL_PROFILING_COMMAND_SUBMIT, b[1]);
|
|
|
|
(*this)[2] = info<nanoseconds>(clGetEventProfilingInfo, h, CL_PROFILING_COMMAND_START, b[2]);
|
|
|
|
(*this)[3] = info<nanoseconds>(clGetEventProfilingInfo, h, CL_PROFILING_COMMAND_END, b[3]);
|
|
|
|
(*this)[4] = info<nanoseconds>(clGetEventProfilingInfo, h, CL_PROFILING_COMMAND_COMPLETE, b[4]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// cl::work (internal)
|
|
|
|
//
|
|
|
|
|
2021-03-20 22:33:40 +01:00
|
|
|
int
|
2021-04-10 00:56:42 +02:00
|
|
|
ircd::cl::wait_event(work &work,
|
|
|
|
const int status,
|
|
|
|
const int desired)
|
2021-03-20 22:33:40 +01:00
|
|
|
{
|
|
|
|
assert(work.handle);
|
2021-04-10 00:56:42 +02:00
|
|
|
assert(status > desired);
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
const bool use_offload
|
|
|
|
{
|
|
|
|
// conf item
|
|
|
|
bool(offload_enable)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto ret
|
|
|
|
{
|
|
|
|
use_offload?
|
|
|
|
wait_event_offload(work, status, desired):
|
|
|
|
wait_event_callback(work, status, desired)
|
|
|
|
};
|
|
|
|
|
|
|
|
const bool is_err
|
|
|
|
{
|
|
|
|
ret < 0
|
|
|
|
};
|
|
|
|
|
2022-03-05 21:30:51 +01:00
|
|
|
const bool is_complete
|
|
|
|
{
|
|
|
|
ret == CL_COMPLETE
|
|
|
|
};
|
|
|
|
|
|
|
|
primary_stats.work_completes += is_complete;
|
2021-04-10 00:56:42 +02:00
|
|
|
primary_stats.work_errors += is_err;
|
|
|
|
primary_stats.work_waits += 1;
|
|
|
|
return ret;
|
|
|
|
}
|
2021-03-20 22:33:40 +01:00
|
|
|
|
2021-04-10 00:56:42 +02:00
|
|
|
int
|
|
|
|
ircd::cl::wait_event_offload(work &work,
|
|
|
|
const int status,
|
|
|
|
const int desired)
|
|
|
|
{
|
|
|
|
completion c
|
|
|
|
{
|
|
|
|
cl_event(work.handle),
|
|
|
|
status,
|
|
|
|
};
|
|
|
|
|
|
|
|
ctx::ole::offload
|
|
|
|
{
|
|
|
|
offload_opts, [&c]
|
|
|
|
{
|
2021-10-15 20:41:22 +02:00
|
|
|
assert(c.status != CL_COMPLETE);
|
2021-04-10 00:56:42 +02:00
|
|
|
call(clWaitForEvents, 1UL, &c.event);
|
2021-10-15 20:41:22 +02:00
|
|
|
c.status = CL_COMPLETE;
|
2021-04-10 00:56:42 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(c.status == CL_COMPLETE);
|
|
|
|
return c.status;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ircd::cl::wait_event_callback(work &work,
|
|
|
|
const int status,
|
|
|
|
const int desired)
|
|
|
|
{
|
2021-04-09 21:13:27 +02:00
|
|
|
// Completion state structure on this ircd::ctx's stack.
|
2021-03-20 22:33:40 +01:00
|
|
|
completion c
|
|
|
|
{
|
|
|
|
cl_event(work.handle),
|
|
|
|
status,
|
|
|
|
};
|
|
|
|
|
2021-04-09 21:13:27 +02:00
|
|
|
// Completion condition closure to be satisfied.
|
2022-06-24 04:18:05 +02:00
|
|
|
const auto condition{[&c, &desired]
|
|
|
|
() noexcept -> bool
|
2021-04-09 21:13:27 +02:00
|
|
|
{
|
|
|
|
return !c.event || c.status <= desired;
|
|
|
|
}};
|
|
|
|
|
|
|
|
// Register callback with OpenCL; note that the callback might be
|
|
|
|
// dispatched immediately from this call itself (see below).
|
2021-03-20 22:33:40 +01:00
|
|
|
call
|
|
|
|
(
|
|
|
|
clSetEventCallback,
|
|
|
|
c.event,
|
|
|
|
desired,
|
2021-04-10 00:56:42 +02:00
|
|
|
&handle_event_callback,
|
2021-03-20 22:33:40 +01:00
|
|
|
&c
|
|
|
|
);
|
|
|
|
|
2021-04-09 21:13:27 +02:00
|
|
|
// This stats item counts clSetEventCallback()'s which return before OpenCL
|
|
|
|
// calls the callback, verifying asynchronicity. If this stats item remains
|
|
|
|
// zero, the OpenCL runtime has hijacked our thread for a blocking wait.
|
|
|
|
primary_stats.work_waits_async += !condition();
|
|
|
|
|
|
|
|
// Yield ircd::ctx while condition unsatisfied
|
|
|
|
c.dock.wait(condition);
|
2021-03-20 22:33:40 +01:00
|
|
|
return c.status;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-04-10 00:56:42 +02:00
|
|
|
ircd::cl::handle_event_callback(cl_event event,
|
|
|
|
cl_int status,
|
|
|
|
void *const priv)
|
2021-03-20 22:33:40 +01:00
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
auto *const c
|
|
|
|
{
|
|
|
|
reinterpret_cast<completion *>(priv)
|
|
|
|
};
|
|
|
|
|
2021-04-09 21:13:27 +02:00
|
|
|
assert(priv != nullptr);
|
2021-03-20 22:33:40 +01:00
|
|
|
assert(event != nullptr);
|
2021-04-09 21:13:27 +02:00
|
|
|
assert(c->event == event);
|
2021-03-20 22:33:40 +01:00
|
|
|
c->status = status;
|
|
|
|
c->dock.notify_one();
|
|
|
|
}
|
|
|
|
|
2021-01-05 23:50:53 +01:00
|
|
|
//
|
|
|
|
// callback surface
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::cl::handle_notify(const char *errstr,
|
|
|
|
const void *token,
|
|
|
|
size_t cb,
|
|
|
|
void *priv)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
if(errstr)
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "OpenCL t:%p cb:%zu :%s",
|
|
|
|
token,
|
|
|
|
cb,
|
|
|
|
errstr,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// util
|
|
|
|
//
|
|
|
|
|
|
|
|
template<class T,
|
2022-03-05 21:28:07 +01:00
|
|
|
int maybe,
|
2021-01-05 23:50:53 +01:00
|
|
|
class F,
|
2022-03-05 21:28:07 +01:00
|
|
|
class id0,
|
2021-01-05 23:50:53 +01:00
|
|
|
class param>
|
|
|
|
T
|
|
|
|
ircd::cl::info(F&& func,
|
2022-03-05 21:28:07 +01:00
|
|
|
const id0 &i0,
|
2021-01-05 23:50:53 +01:00
|
|
|
const param &p,
|
2022-03-05 21:28:07 +01:00
|
|
|
const mutable_buffer &out,
|
|
|
|
T default_)
|
2021-01-05 23:50:53 +01:00
|
|
|
{
|
2021-01-08 09:53:12 +01:00
|
|
|
using ircd::data;
|
|
|
|
using ircd::size;
|
|
|
|
|
2021-01-05 23:50:53 +01:00
|
|
|
size_t len {0};
|
2022-03-05 21:28:07 +01:00
|
|
|
const auto code
|
2021-01-05 23:50:53 +01:00
|
|
|
{
|
2022-03-05 21:28:07 +01:00
|
|
|
call<maybe>(std::forward<F>(func), i0, p, size(out), data(out), &len)
|
2021-01-05 23:50:53 +01:00
|
|
|
};
|
|
|
|
|
2022-03-05 21:28:07 +01:00
|
|
|
assert(code == CL_SUCCESS || code == maybe);
|
|
|
|
if constexpr(maybe != CL_SUCCESS)
|
|
|
|
if(code == maybe)
|
|
|
|
return default_;
|
|
|
|
|
|
|
|
return byte_view<T>
|
|
|
|
{
|
|
|
|
string_view
|
|
|
|
{
|
|
|
|
data(out), len
|
|
|
|
}
|
|
|
|
};
|
2021-01-05 23:50:53 +01:00
|
|
|
}
|
|
|
|
|
2021-04-03 21:22:56 +02:00
|
|
|
template<class T,
|
2022-03-05 21:28:07 +01:00
|
|
|
int maybe,
|
2021-04-03 21:22:56 +02:00
|
|
|
class F,
|
|
|
|
class id0,
|
|
|
|
class id1,
|
|
|
|
class param>
|
|
|
|
T
|
|
|
|
ircd::cl::info(F&& func,
|
|
|
|
const id0 &i0,
|
|
|
|
const id1 &i1,
|
|
|
|
const param &p,
|
2022-03-05 21:28:07 +01:00
|
|
|
const mutable_buffer &out,
|
|
|
|
T default_)
|
2021-04-03 21:22:56 +02:00
|
|
|
{
|
|
|
|
using ircd::data;
|
|
|
|
using ircd::size;
|
|
|
|
|
|
|
|
size_t len {0};
|
2022-03-05 21:28:07 +01:00
|
|
|
const auto code
|
2021-04-03 21:22:56 +02:00
|
|
|
{
|
2022-03-05 21:28:07 +01:00
|
|
|
call<maybe>(std::forward<F>(func), i0, i1, p, size(out), data(out), &len)
|
2021-04-03 21:22:56 +02:00
|
|
|
};
|
|
|
|
|
2022-03-05 21:28:07 +01:00
|
|
|
assert(code == CL_SUCCESS || code == maybe);
|
|
|
|
if constexpr(maybe != CL_SUCCESS)
|
|
|
|
if(code == maybe)
|
|
|
|
return default_;
|
|
|
|
|
|
|
|
return byte_view<T>
|
|
|
|
{
|
|
|
|
string_view
|
|
|
|
{
|
|
|
|
data(out), len
|
|
|
|
}
|
|
|
|
};
|
2021-04-03 21:22:56 +02:00
|
|
|
}
|
|
|
|
|
2022-03-05 21:28:07 +01:00
|
|
|
template<int maybe,
|
|
|
|
class func,
|
2021-01-05 23:50:53 +01:00
|
|
|
class... args>
|
|
|
|
int
|
|
|
|
ircd::cl::call(func&& f,
|
|
|
|
args&&... a)
|
|
|
|
{
|
|
|
|
const int ret
|
|
|
|
{
|
|
|
|
f(std::forward<args>(a)...)
|
|
|
|
};
|
|
|
|
|
2022-03-05 21:28:07 +01:00
|
|
|
if constexpr(maybe != CL_SUCCESS)
|
|
|
|
if(ret == maybe)
|
|
|
|
return ret;
|
|
|
|
|
2021-01-05 23:50:53 +01:00
|
|
|
return throw_on_error(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ircd::cl::throw_on_error(const int &code)
|
|
|
|
{
|
|
|
|
if(unlikely(is_error(code)))
|
|
|
|
throw opencl_error
|
|
|
|
{
|
2021-03-19 18:11:10 +01:00
|
|
|
"(%d) :%s",
|
2021-01-05 23:50:53 +01:00
|
|
|
code,
|
|
|
|
reflect_error(code),
|
|
|
|
};
|
|
|
|
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::cl::is_error(const int &code)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return code < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::cl::reflect_error(const int code)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
switch(code)
|
|
|
|
{
|
|
|
|
case CL_SUCCESS: return "SUCCESS";
|
|
|
|
case CL_DEVICE_NOT_FOUND: return "DEVICE_NOT_FOUND";
|
|
|
|
case CL_DEVICE_NOT_AVAILABLE: return "DEVICE_NOT_AVAILABLE";
|
|
|
|
case CL_COMPILER_NOT_AVAILABLE: return "COMPILER_NOT_AVAILABLE";
|
|
|
|
case CL_MEM_OBJECT_ALLOCATION_FAILURE: return "MEM_OBJECT_ALLOCATION_FAILURE";
|
|
|
|
case CL_OUT_OF_RESOURCES: return "OUT_OF_RESOURCES";
|
|
|
|
case CL_OUT_OF_HOST_MEMORY: return "OUT_OF_HOST_MEMORY";
|
|
|
|
case CL_PROFILING_INFO_NOT_AVAILABLE: return "PROFILING_INFO_NOT_AVAILABLE";
|
|
|
|
case CL_MEM_COPY_OVERLAP: return "MEM_COPY_OVERLAP";
|
|
|
|
case CL_IMAGE_FORMAT_MISMATCH: return "IMAGE_FORMAT_MISMATCH";
|
|
|
|
case CL_IMAGE_FORMAT_NOT_SUPPORTED: return "IMAGE_FORMAT_NOT_SUPPORTED";
|
|
|
|
case CL_BUILD_PROGRAM_FAILURE: return "BUILD_PROGRAM_FAILURE";
|
|
|
|
case CL_MAP_FAILURE: return "MAP_FAILURE";
|
|
|
|
case CL_INVALID_VALUE: return "INVALID_VALUE";
|
|
|
|
case CL_INVALID_DEVICE_TYPE: return "INVALID_DEVICE_TYPE";
|
|
|
|
case CL_INVALID_PLATFORM: return "INVALID_PLATFORM";
|
|
|
|
case CL_INVALID_DEVICE: return "INVALID_DEVICE";
|
|
|
|
case CL_INVALID_CONTEXT: return "INVALID_CONTEXT";
|
|
|
|
case CL_INVALID_QUEUE_PROPERTIES: return "INVALID_QUEUE_PROPERTIES";
|
|
|
|
case CL_INVALID_COMMAND_QUEUE: return "INVALID_COMMAND_QUEUE";
|
|
|
|
case CL_INVALID_HOST_PTR: return "INVALID_HOST_PTR";
|
|
|
|
case CL_INVALID_MEM_OBJECT: return "INVALID_MEM_OBJECT";
|
|
|
|
case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: return "INVALID_IMAGE_FORMAT_DESCRIPTOR";
|
|
|
|
case CL_INVALID_IMAGE_SIZE: return "INVALID_IMAGE_SIZE";
|
|
|
|
case CL_INVALID_SAMPLER: return "INVALID_SAMPLER";
|
|
|
|
case CL_INVALID_BINARY: return "INVALID_BINARY";
|
|
|
|
case CL_INVALID_BUILD_OPTIONS: return "INVALID_BUILD_OPTIONS";
|
|
|
|
case CL_INVALID_PROGRAM: return "INVALID_PROGRAM";
|
|
|
|
case CL_INVALID_PROGRAM_EXECUTABLE: return "INVALID_PROGRAM_EXECUTABLE";
|
|
|
|
case CL_INVALID_KERNEL_NAME: return "INVALID_KERNEL_NAME";
|
|
|
|
case CL_INVALID_KERNEL_DEFINITION: return "INVALID_KERNEL_DEFINITION";
|
|
|
|
case CL_INVALID_KERNEL: return "INVALID_KERNEL";
|
|
|
|
case CL_INVALID_ARG_INDEX: return "INVALID_ARG_INDEX";
|
|
|
|
case CL_INVALID_ARG_VALUE: return "INVALID_ARG_VALUE";
|
|
|
|
case CL_INVALID_ARG_SIZE: return "INVALID_ARG_SIZE";
|
|
|
|
case CL_INVALID_KERNEL_ARGS: return "INVALID_KERNEL_ARGS";
|
|
|
|
case CL_INVALID_WORK_DIMENSION: return "INVALID_WORK_DIMENSION";
|
|
|
|
case CL_INVALID_WORK_GROUP_SIZE: return "INVALID_WORK_GROUP_SIZE";
|
|
|
|
case CL_INVALID_WORK_ITEM_SIZE: return "INVALID_WORK_ITEM_SIZE";
|
|
|
|
case CL_INVALID_GLOBAL_OFFSET: return "INVALID_GLOBAL_OFFSET";
|
|
|
|
case CL_INVALID_EVENT_WAIT_LIST: return "INVALID_EVENT_WAIT_LIST";
|
|
|
|
case CL_INVALID_EVENT: return "INVALID_EVENT";
|
|
|
|
case CL_INVALID_OPERATION: return "INVALID_OPERATION";
|
|
|
|
case CL_INVALID_GL_OBJECT: return "INVALID_GL_OBJECT";
|
|
|
|
case CL_INVALID_BUFFER_SIZE: return "INVALID_BUFFER_SIZE";
|
|
|
|
case CL_INVALID_MIP_LEVEL: return "INVALID_MIP_LEVEL";
|
|
|
|
case CL_INVALID_GLOBAL_WORK_SIZE: return "INVALID_GLOBAL_WORK_SIZE";
|
|
|
|
|
|
|
|
#ifdef CL_VERSION_1_1
|
|
|
|
case CL_INVALID_PROPERTY: return "INVALID_PROPERTY";
|
|
|
|
case CL_MISALIGNED_SUB_BUFFER_OFFSET: return "MISALIGNED_SUB_BUFFER_OFFSET";
|
|
|
|
case CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST: return "EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CL_VERSION_1_2
|
|
|
|
case CL_COMPILE_PROGRAM_FAILURE: return "COMPILE_PROGRAM_FAILURE";
|
|
|
|
case CL_LINKER_NOT_AVAILABLE: return "LINKER_NOT_AVAILABLE";
|
|
|
|
case CL_LINK_PROGRAM_FAILURE: return "LINK_PROGRAM_FAILURE";
|
|
|
|
case CL_DEVICE_PARTITION_FAILED: return "DEVICE_PARTITION_FAILED";
|
|
|
|
case CL_KERNEL_ARG_INFO_NOT_AVAILABLE: return "KERNEL_ARG_INFO_NOT_AVAILABLE";
|
|
|
|
case CL_INVALID_IMAGE_DESCRIPTOR: return "INVALID_IMAGE_DESCRIPTOR";
|
|
|
|
case CL_INVALID_COMPILER_OPTIONS: return "INVALID_COMPILER_OPTIONS";
|
|
|
|
case CL_INVALID_LINKER_OPTIONS: return "INVALID_LINKER_OPTIONS";
|
|
|
|
case CL_INVALID_DEVICE_PARTITION_COUNT: return "INVALID_DEVICE_PARTITION_COUNT";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CL_VERSION_2_0
|
|
|
|
case CL_INVALID_PIPE_SIZE: return "INVALID_PIPE_SIZE";
|
|
|
|
case CL_INVALID_DEVICE_QUEUE: return "INVALID_DEVICE_QUEUE";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CL_VERSION_2_2
|
|
|
|
case CL_INVALID_SPEC_ID: return "INVALID_SPEC_ID";
|
|
|
|
case CL_MAX_SIZE_RESTRICTION_EXCEEDED: return "MAX_SIZE_RESTRICTION_EXCEEDED";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return "???????";
|
|
|
|
}
|