1/* @ajax/nvjitlink: nvJitLink, opened at runtime (dlopen), compiles a program's
2 * PTX to a cubin outside the blink window (mesh-host nvjitlink.rs): the
3 * driver's own JIT would run inside it, and module loads block while any
4 * kernel of the context runs. It needs no CUDA context, so it runs on any
5 * thread. There is no fallback to the driver JIT: a missing library is an
6 * error and meshd refuses to start. */
7#ifndef MESH_NVJITLINK_H
8#define MESH_NVJITLINK_H
910#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
1314#define MESH_NVJITLINK_LIB "libnvJitLink.so.13"
1516/* The CUDA 13.0 entry points (the versioned symbols nvJitLink.h's inline wrappers call). */
17typedef struct {
18 int (*create)(void **h, uint32_t n, const char *const *opts); /* __nvJitLinkCreate_13_0 */
19 int (*destroy)(void **h); /* __nvJitLinkDestroy_13_0 */
20 int (*add_data)(void *h, int kind, const void *data, size_t n, const char *name); /* __nvJitLinkAddData_13_0 */
21 int (*complete)(void *h); /* __nvJitLinkComplete_13_0 */
22 int (*cubin_size)(void *h, size_t *n); /* __nvJitLinkGetLinkedCubinSize_13_0 */
23 int (*cubin)(void *h, void *out); /* __nvJitLinkGetLinkedCubin_13_0 */
24 int (*err_size)(void *h, size_t *n); /* __nvJitLinkGetErrorLogSize_13_0 */
25 int (*err_log)(void *h, void *out); /* __nvJitLinkGetErrorLog_13_0 */
26} mesh_nvjitlink_fns;
2728typedef struct {
29 char *path;
30 uint32_t major, minor;
31 mesh_nvjitlink_fns fns;
32} mesh_nvjitlink;
3334/* dlopen dir/libnvJitLink.so.13 and resolve the entry points; version 13 only.
35 * False with *err: "nvJitLink: cannot open /x/libnvJitLink.so.13: ... (set --nvjitlink DIR; there is no fallback)". */
36bool mesh_nvjitlink_open(const char *dir, mesh_nvjitlink *out, char **err);
37/* A linker over given functions (tests). */
38void mesh_nvjitlink_from(const mesh_nvjitlink_fns *fns, mesh_nvjitlink *out);
39/* PTX text -> cubin for arch ("sm_121"); reg_cap: -maxrregcount (0: the compiler's choice).
40 * *cubin is malloc'd. The error carries nvJitLink's error log. */
41bool mesh_nvjitlink_ptx_to_cubin(const mesh_nvjitlink *j, const uint8_t *ptx, size_t n, const char *arch, uint32_t reg_cap,
42 uint8_t **cubin, size_t *cubin_len, char **err);
43void mesh_nvjitlink_free(mesh_nvjitlink *j);
4445#endif