igneum/proto-cuda/nvrtc/cuda_api.h
igneum-labs f535abb59d One-click CUDA worker: driver API + NVRTC loaded at run time, pack read at run time, Mac emulation check
proto-cuda/nvrtc/worker.cpp serves igneum-miner's worker protocol with nothing installed but the NVIDIA driver:
nvcuda.dll and the redistributable nvrtc64_120_0.dll are opened with LoadLibrary (cuda_api.h), the pack's kernel.cu
and kernel_bound.cu are handed to NVRTC byte for byte up to the host launch wrappers with program.h and memhard.h as
named headers, every pack is self-tested against its vectors.h (cache head, last line, FNV-1a 64, dataset head, last
word, 64 samples, 96 vector lanes) before it serves a job, prepare runs on a thread for the hourly swap, and a job on
seeds without a pair makes the worker find the miner's pack by seeds.txt and build it. packfile.h (C99) reads a pack
directory. fetch-redist.sh verifies and stages the NVIDIA 12.8.93 redistributables and the Khronos headers
(THIRD-PARTY.md records URLs, hashes and the EULA clause); build-windows.sh cross-compiles with mingw (static,
KERNEL32 + Universal CRT only). emu/: the two libraries as host functions, the pack kernels on host threads, the NVRTC
source compared with the pack files; test.sh PASS on the Mac (two real packs, swap, self-heal, 17 sampled hashes equal
igneum-pow hash-bound). Not run here: the real NVRTC compile and driver load (RTX 5090 PC).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-04 09:55:05 +00:00

61 lines
3.1 KiB
C

// cuda_api.h: the slice of the CUDA driver API and of NVRTC that igneum-worker-cuda calls, as function pointers.
// worker.cpp fills them from nvcuda.dll (the driver) and nvrtc64_*.dll (shipped next to the exe) with
// LoadLibrary/GetProcAddress, so no import library is linked and the exe cross-compiles with mingw on the Mac.
// The emulation build (emu/emu_backend.cpp) fills the same table with host functions. 4 October 2026.
#pragma once
#include <cuda.h>
#include <nvrtc.h>
struct Drv {
decltype(&cuInit) init = nullptr;
decltype(&cuDriverGetVersion) driverGetVersion = nullptr;
decltype(&cuDeviceGetCount) deviceGetCount = nullptr;
decltype(&cuDeviceGet) deviceGet = nullptr;
decltype(&cuDeviceGetName) deviceGetName = nullptr;
decltype(&cuDeviceGetAttribute) deviceGetAttribute = nullptr;
decltype(&cuDeviceTotalMem_v2) deviceTotalMem = nullptr;
decltype(&cuDevicePrimaryCtxSetFlags_v2) primaryCtxSetFlags = nullptr;
decltype(&cuDevicePrimaryCtxRetain) primaryCtxRetain = nullptr;
decltype(&cuDevicePrimaryCtxRelease_v2) primaryCtxRelease = nullptr;
decltype(&cuCtxSetCurrent) ctxSetCurrent = nullptr;
decltype(&cuCtxSynchronize) ctxSynchronize = nullptr;
decltype(&cuMemGetInfo_v2) memGetInfo = nullptr;
decltype(&cuMemAlloc_v2) memAlloc = nullptr;
decltype(&cuMemFree_v2) memFree = nullptr;
decltype(&cuMemcpyDtoH_v2) memcpyDtoH = nullptr;
decltype(&cuModuleLoadData) moduleLoadData = nullptr;
decltype(&cuModuleUnload) moduleUnload = nullptr;
decltype(&cuModuleGetFunction) moduleGetFunction = nullptr;
decltype(&cuLaunchKernel) launchKernel = nullptr;
decltype(&cuStreamCreate) streamCreate = nullptr;
decltype(&cuStreamSynchronize) streamSynchronize = nullptr;
decltype(&cuStreamDestroy_v2) streamDestroy = nullptr;
decltype(&cuFuncGetAttribute) funcGetAttribute = nullptr;
decltype(&cuOccupancyMaxActiveBlocksPerMultiprocessor) occupancy = nullptr;
decltype(&cuGetErrorString) getErrorString = nullptr;
decltype(&cuGetErrorName) getErrorName = nullptr;
};
struct Rtc {
decltype(&nvrtcVersion) version = nullptr;
decltype(&nvrtcGetNumSupportedArchs) getNumSupportedArchs = nullptr; // CUDA 11.2 and newer; optional
decltype(&nvrtcGetSupportedArchs) getSupportedArchs = nullptr;
decltype(&nvrtcCreateProgram) createProgram = nullptr;
decltype(&nvrtcDestroyProgram) destroyProgram = nullptr;
decltype(&nvrtcCompileProgram) compileProgram = nullptr;
decltype(&nvrtcGetProgramLogSize) getProgramLogSize = nullptr;
decltype(&nvrtcGetProgramLog) getProgramLog = nullptr;
decltype(&nvrtcGetPTXSize) getPTXSize = nullptr;
decltype(&nvrtcGetPTX) getPTX = nullptr;
decltype(&nvrtcGetCUBINSize) getCUBINSize = nullptr;
decltype(&nvrtcGetCUBIN) getCUBIN = nullptr;
decltype(&nvrtcAddNameExpression) addNameExpression = nullptr;
decltype(&nvrtcGetLoweredName) getLoweredName = nullptr;
decltype(&nvrtcGetErrorString) getErrorString = nullptr;
};
#ifdef IGNEUM_EMU
// emu/emu_backend.cpp: host functions in place of the two libraries (the pack's kernels run on host threads)
void emu_fill_driver(Drv& d);
void emu_fill_nvrtc(Rtc& r);
#endif