igneum/proto-opencl/cl_dynamic.h
igneum-labs 1028c2579f Miner dev fee: app switch and UI line, HiveOS package, Linux worker cross-build, docs and public text
Decision of 4 October 2026 (evening): the Igneum Miner software takes a visible, switchable 1% dev fee, the norm
for GPU miners; the protocol stays fee-free. The miner side (--dev-fee, the 1-in-100 template counter, the audit
command) is on branch dev-fee of the node fork.

- app: settings.dev_fee (default on) passes --dev-fee 0 to igneum-miner when off; Settings shows the miner's own
  "dev fee 1% (1 block in 100) to 0x..." line next to the rewards address with a switch; the engine parses the
  miner's start line and its dev-fee block lines (fee_session, lifetime fee_total, an event per fee block)
- packaging/hive: h-manifest.conf, h-config.sh, h-run.sh, h-stats.sh, make-hive-package.sh (igneum-hive-<v>.tar.gz
  with the Linux igneumd, igneum-miner and both GPU workers), README with the Flight Sheet, selftest.sh (bash -n,
  stub binaries, the three hooks the way Hive runs them, the stats JSON parsed). Hive itself is untested
- infra/cross/build-workers-linux.sh: the NVRTC and OpenCL workers cross-compiled for Linux with zig;
  proto-opencl/cl_dynamic.h gains the Linux dlopen branch (libOpenCL.so.1)
- tools/dev-fee/run.mjs: the fee-block test network (two nodes on 29900+, three CPU miners, payouts audit)
- docs/design/miner-dev-fee.md (mechanism, flag, lines, the DEV_FEE_ADDRESS placeholder and the devnet address),
  docs/fud-ledger.md E18 and the E5/L9 status line, litepaper "What a miner's hour looks like" paragraph, homepage
  miner section note

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-04 21:46:41 +00:00

91 lines
4.5 KiB
C

/* cl_dynamic.h: OpenCL.dll loaded at run time (Windows). 4 October 2026.
*
* The one-click AMD worker (host.c cross-compiled with mingw, build-windows.sh) links no OpenCL import library:
* every cl* entry point host.c calls is a function pointer filled from OpenCL.dll with LoadLibrary/GetProcAddress.
* OpenCL.dll is the Khronos ICD loader that the AMD Adrenalin (and NVIDIA, Intel) driver installs in System32, so
* nothing but the driver is needed on the PC. Included by host.c after <CL/cl.h> when IGNEUM_CL_DYNAMIC is defined;
* the macros below then rename the calls in the rest of the file. The Mac and Linux builds link the library as before.
*/
#ifndef IGNEUM_CL_DYNAMIC_H
#define IGNEUM_CL_DYNAMIC_H
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#include <dlfcn.h>
#endif
#include <stdio.h>
#define IG_CL_FUNCS(X) \
X(clGetPlatformIDs) X(clGetPlatformInfo) X(clGetDeviceIDs) X(clGetDeviceInfo) X(clCreateContext) \
X(clCreateCommandQueue) X(clCreateProgramWithSource) X(clBuildProgram) X(clGetProgramBuildInfo) X(clCreateKernel) \
X(clSetKernelArg) X(clEnqueueNDRangeKernel) X(clEnqueueReadBuffer) X(clEnqueueWriteBuffer) X(clCreateBuffer) \
X(clReleaseMemObject) X(clReleaseKernel) X(clReleaseProgram) X(clReleaseCommandQueue) X(clReleaseContext) \
X(clFinish) X(clWaitForEvents) X(clReleaseEvent) X(clGetEventInfo) X(clGetEventProfilingInfo) X(clGetKernelWorkGroupInfo) \
X(clGetExtensionFunctionAddressForPlatform)
/* One pointer per entry point, typed from the header's declaration (so a signature drift is a compile error). */
#define IG_CL_DECL(f) static __typeof__(f)* ig_##f = NULL;
IG_CL_FUNCS(IG_CL_DECL)
#undef IG_CL_DECL
static char ig_cl_error[512];
/* Returns 1 when OpenCL.dll and every entry point are there; else 0 with ig_cl_error set. */
static int ig_cl_load(void) {
#ifdef _WIN32
HMODULE h = LoadLibraryA("OpenCL.dll");
if (!h) {
snprintf(ig_cl_error, sizeof(ig_cl_error), "OpenCL.dll is not installed (the GPU driver provides it: AMD Adrenalin, or the NVIDIA or Intel driver); nothing else is needed");
return 0;
}
#define IG_CL_LOAD(f) ig_##f = (__typeof__(f)*)(void*)GetProcAddress(h, #f); if (!ig_##f) { snprintf(ig_cl_error, sizeof(ig_cl_error), "OpenCL.dll lacks %s", #f); return 0; }
IG_CL_FUNCS(IG_CL_LOAD)
#undef IG_CL_LOAD
return 1;
#else
/* Linux (the HiveOS package, 4 October 2026): the ICD loader the GPU driver installs (ROCm, amdgpu-pro, NVIDIA,
* Intel all register with it), opened at run time so the worker cross-compiles on the Mac with no OpenCL library. */
void* h = dlopen("libOpenCL.so.1", RTLD_NOW);
if (!h) h = dlopen("libOpenCL.so", RTLD_NOW);
if (!h) {
snprintf(ig_cl_error, sizeof(ig_cl_error), "libOpenCL.so.1 is not installed (the GPU driver provides it: ROCm or amdgpu-pro for AMD, the NVIDIA or Intel driver); nothing else is needed");
return 0;
}
#define IG_CL_LOAD(f) ig_##f = (__typeof__(f)*)dlsym(h, #f); if (!ig_##f) { snprintf(ig_cl_error, sizeof(ig_cl_error), "libOpenCL.so.1 lacks %s", #f); return 0; }
IG_CL_FUNCS(IG_CL_LOAD)
#undef IG_CL_LOAD
return 1;
#endif
}
/* From here on, host.c's calls go through the pointers. */
#define IG_CL_RENAME(f)
#define clGetPlatformIDs ig_clGetPlatformIDs
#define clGetPlatformInfo ig_clGetPlatformInfo
#define clGetDeviceIDs ig_clGetDeviceIDs
#define clGetDeviceInfo ig_clGetDeviceInfo
#define clCreateContext ig_clCreateContext
#define clCreateCommandQueue ig_clCreateCommandQueue
#define clCreateProgramWithSource ig_clCreateProgramWithSource
#define clBuildProgram ig_clBuildProgram
#define clGetProgramBuildInfo ig_clGetProgramBuildInfo
#define clCreateKernel ig_clCreateKernel
#define clSetKernelArg ig_clSetKernelArg
#define clEnqueueNDRangeKernel ig_clEnqueueNDRangeKernel
#define clEnqueueReadBuffer ig_clEnqueueReadBuffer
#define clEnqueueWriteBuffer ig_clEnqueueWriteBuffer
#define clCreateBuffer ig_clCreateBuffer
#define clReleaseMemObject ig_clReleaseMemObject
#define clReleaseKernel ig_clReleaseKernel
#define clReleaseProgram ig_clReleaseProgram
#define clReleaseCommandQueue ig_clReleaseCommandQueue
#define clReleaseContext ig_clReleaseContext
#define clFinish ig_clFinish
#define clWaitForEvents ig_clWaitForEvents
#define clReleaseEvent ig_clReleaseEvent
#define clGetEventInfo ig_clGetEventInfo
#define clGetEventProfilingInfo ig_clGetEventProfilingInfo
#define clGetKernelWorkGroupInfo ig_clGetKernelWorkGroupInfo
#define clGetExtensionFunctionAddressForPlatform ig_clGetExtensionFunctionAddressForPlatform
#endif