@nosana/node 1.1.78-rc → 1.1.79-rc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/.env CHANGED
@@ -1,6 +1,6 @@
1
1
  BACKEND_SOLANA_ADDRESS=7rFPFnxjXHC2sfDy3qrDa9pEb4j49oivMuV7e8sYDPmB
2
2
  FRP_SERVER_IMAGE=registry.hub.docker.com/nosana/frpc:v1.0.45
3
- JOB_RUNTIME_IMAGE="nosana/job-runtime:v0.2.3"
3
+ JOB_RUNTIME_IMAGE="nosana/job-runtime:v0.2.4"
4
4
  RESOURCE_MANAGER_IMAGE=registry.hub.docker.com/nosana/resource-manager:v1.1.19
5
5
  FRP_SERVER_PORT=7000
6
6
  MIN_DISK_SPACE=25
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosana/node",
3
- "version": "1.1.78-rc",
3
+ "version": "1.1.79-rc",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "nosana-node": "./dist/src/index.js"
@@ -1,3 +1,3 @@
1
1
  import { ContainerCreateOptions } from "dockerode";
2
2
  import { RunContainerArgs } from "../interface.js";
3
- export declare function createDockerRunOptions(image: string, { name, cmd, gpu, volumes, env, work_dir, entrypoint, aliases, restart_policy, runtime, bind_network_to_container, labels, security, pid_mode, user, group_add, }: RunContainerArgs, gpuOption: string): ContainerCreateOptions;
3
+ export declare function createDockerRunOptions(image: string, { name, cmd, gpu, volumes, env, work_dir, entrypoint, aliases, restart_policy, runtime, bind_network_to_container, labels, security, user, group_add, }: RunContainerArgs, gpuOption: string): ContainerCreateOptions;
@@ -10,7 +10,7 @@ function parseRestartPolicy(restart_policy) {
10
10
  }
11
11
  return undefined;
12
12
  }
13
- export function createDockerRunOptions(image, { name, cmd, gpu, volumes, env, work_dir, entrypoint, aliases, restart_policy, runtime, bind_network_to_container, labels, security, pid_mode, user, group_add, }, gpuOption) {
13
+ export function createDockerRunOptions(image, { name, cmd, gpu, volumes, env, work_dir, entrypoint, aliases, restart_policy, runtime, bind_network_to_container, labels, security, user, group_add, }, gpuOption) {
14
14
  const devices = [];
15
15
  if (gpu) {
16
16
  devices.push({
@@ -76,7 +76,6 @@ export function createDockerRunOptions(image, { name, cmd, gpu, volumes, env, wo
76
76
  ...(security?.noNewPrivileges
77
77
  ? { SecurityOpt: ['no-new-privileges'] }
78
78
  : {}),
79
- ...(pid_mode ? { PidMode: pid_mode } : {}),
80
79
  ...(group_add ? { GroupAdd: group_add } : {}),
81
80
  },
82
81
  };
@@ -38,8 +38,6 @@ export type RunContainerArgs = {
38
38
  /** Keeps the container's processes from gaining privileges (setuid etc.). */
39
39
  noNewPrivileges?: boolean;
40
40
  };
41
- /** Shares the host's pid namespace with the container (`--pid=host`). */
42
- pid_mode?: 'host';
43
41
  /** The user (`uid[:gid]`) the container runs as; the image's by default. */
44
42
  user?: string;
45
43
  /** Supplementary groups (gids) for the container's user (`--group-add`). */
@@ -9,9 +9,6 @@ import type { RunContainerArgs } from '../../interface.js';
9
9
  export declare function createPodmanRunOptions(image: string, args: RunContainerArgs, gpuOption: string): {
10
10
  groups?: string[] | undefined;
11
11
  user?: string | undefined;
12
- pidns?: {
13
- nsmode: "host";
14
- } | undefined;
15
12
  no_new_privileges?: boolean | undefined;
16
13
  resource_limits?: {
17
14
  pids: {
@@ -59,9 +56,6 @@ export declare function createPodmanRunOptions(image: string, args: RunContainer
59
56
  } | {
60
57
  groups?: string[] | undefined;
61
58
  user?: string | undefined;
62
- pidns?: {
63
- nsmode: "host";
64
- } | undefined;
65
59
  no_new_privileges?: boolean | undefined;
66
60
  resource_limits?: {
67
61
  pids: {
@@ -110,9 +104,6 @@ export declare function createPodmanRunOptions(image: string, args: RunContainer
110
104
  } | {
111
105
  groups?: string[] | undefined;
112
106
  user?: string | undefined;
113
- pidns?: {
114
- nsmode: "host";
115
- } | undefined;
116
107
  no_new_privileges?: boolean | undefined;
117
108
  resource_limits?: {
118
109
  pids: {
@@ -24,7 +24,7 @@ function parseRestartPolicy(restart_policy) {
24
24
  * @returns
25
25
  */
26
26
  export function createPodmanRunOptions(image, args, gpuOption) {
27
- const { name, cmd, gpu, volumes, env, aliases, work_dir, entrypoint, restart_policy, labels, security, runtime, pid_mode, user, group_add, } = args;
27
+ const { name, cmd, gpu, volumes, env, aliases, work_dir, entrypoint, restart_policy, labels, security, runtime, user, group_add, } = args;
28
28
  const devices = gpu
29
29
  ? gpuOption === 'all'
30
30
  ? [
@@ -80,7 +80,6 @@ export function createPodmanRunOptions(image, args, gpuOption) {
80
80
  ? { resource_limits: { pids: { limit: security.pidsLimit } } }
81
81
  : {}),
82
82
  ...(security?.noNewPrivileges ? { no_new_privileges: true } : {}),
83
- ...(pid_mode ? { pidns: { nsmode: pid_mode } } : {}),
84
83
  ...(user ? { user } : {}),
85
84
  ...(group_add ? { groups: group_add } : {}),
86
85
  };
@@ -3,14 +3,13 @@
3
3
  *
4
4
  * By default it runs the one job named by `JOB_ADDRESS` (see runtime/runJob.ts).
5
5
  *
6
- * With `--probe` it is a readiness probe for the image instead: it checks the
7
- * two things the GPU stats sampling depends on, that the runtime mounted
8
- * `nvidia-smi` into the container and that `/proc` shows the host's process
9
- * tree, and prints what it found. Exit code 0 means the image is fit to host
10
- * the sidecar on this machine.
6
+ * With `--probe` it is a readiness probe for the image instead: it checks
7
+ * that the runtime mounted `nvidia-smi` into the container, which the GPU
8
+ * stats sampling depends on, and that it runs unprivileged, and prints what
9
+ * it found. Exit code 0 means the image is fit to host the sidecar on this
10
+ * machine.
11
11
  */
12
12
  import { execFile } from 'child_process';
13
- import { readFile } from 'fs/promises';
14
13
  import { promisify } from 'util';
15
14
  import { readJobRuntimeServerConfig } from './config.js';
16
15
  import { runJob } from './runtime/runJob.js';
@@ -27,33 +26,16 @@ async function probeNvidiaSmi() {
27
26
  return { ok: false, detail: error?.message ?? String(error) };
28
27
  }
29
28
  }
30
- /**
31
- * In the host pid namespace pid 1 is the host's init, not this process; in a
32
- * private namespace this node process is pid 1 itself. Read the way the
33
- * sampler reads ancestry: straight from `/proc`.
34
- */
35
- async function probeHostPids() {
36
- try {
37
- const init = (await readFile('/proc/1/comm', 'utf8')).trim();
38
- return { ok: process.pid !== 1 && init !== 'node', detail: `pid 1 is ${init}` };
39
- }
40
- catch (error) {
41
- return { ok: false, detail: error?.message ?? String(error) };
42
- }
43
- }
44
29
  /** The sidecar runs as the image's unprivileged user, never as root. */
45
30
  function probeUser() {
46
31
  const uid = process.getuid?.();
47
32
  return { ok: uid !== undefined && uid !== 0, detail: `uid ${uid}` };
48
33
  }
49
34
  async function probe() {
50
- const [nvidiaSmi, hostPids] = await Promise.all([
51
- probeNvidiaSmi(),
52
- probeHostPids(),
53
- ]);
35
+ const nvidiaSmi = await probeNvidiaSmi();
54
36
  const user = probeUser();
55
- console.log(JSON.stringify({ nvidiaSmi, hostPids, user }, null, 2));
56
- process.exit(nvidiaSmi.ok && hostPids.ok && user.ok ? 0 : 1);
37
+ console.log(JSON.stringify({ nvidiaSmi, user }, null, 2));
38
+ process.exit(nvidiaSmi.ok && user.ok ? 0 : 1);
57
39
  }
58
40
  /**
59
41
  * Runs the job named by `JOB_ADDRESS` (see config.ts for the rest of the
@@ -6,7 +6,7 @@ import { ExposedPortHealthCheck, } from './ExposedPortHealthCheck.js';
6
6
  import { generateProxies, generateUrlSecretObject } from './expose.js';
7
7
  import { withSshSidecar } from './sshSidecar.js';
8
8
  import { promiseTimeoutWrapper } from './timeoutPromiseWrapper.js';
9
- import { attributeGpuStats } from './gpu/gpuStats.js';
9
+ import { gpuStats } from './gpu/gpuStats.js';
10
10
  /**
11
11
  * Runs a job's operations as containers: pulls their images, fetches their
12
12
  * remote resources, publishes their exposed ports through frpc (with an SSH
@@ -209,7 +209,7 @@ export class ContainerProvider {
209
209
  emitter.emit('setContainerInternalIp', startedInfo.NetworkSettings.Networks["NOSANA_GATEWAY"].IPAddress);
210
210
  }
211
211
  stateManager = new ContainerStateManager(container, controller, emitter, op.args.restart_policy, restartsOnUnhealthy, gpu && this.config.gpu
212
- ? containerGpuStat(container, this.config.gpu)
212
+ ? containerGpuStat(this.config.gpu)
213
213
  : undefined);
214
214
  // The logs up to the earlier sidecar's last line are in the records;
215
215
  // the stream picks up after it.
@@ -488,16 +488,10 @@ function getAliases(args) {
488
488
  return args.aliases.split(',');
489
489
  return args.aliases;
490
490
  }
491
- /**
492
- * A GPU container's share of the host's GPUs, by the processes under its root
493
- * process. Inspected per reading: a restart gives the container a new one.
494
- */
495
- function containerGpuStat(container, sample) {
491
+ /** A GPU container's stat: the host's GPUs in whole (see gpuStats). */
492
+ function containerGpuStat(sample) {
496
493
  return async () => {
497
- const pid = (await container.inspect()).State?.Pid ?? 0;
498
- if (!(pid > 0))
499
- return undefined;
500
- const snapshot = await sample();
501
- return snapshot ? attributeGpuStats(snapshot, pid) : undefined;
494
+ const devices = await sample();
495
+ return devices ? gpuStats(devices) : undefined;
502
496
  };
503
497
  }
@@ -1,24 +1,14 @@
1
- import { GpuSnapshot } from './gpuStats.js';
2
- /** One host-wide GPU reading, or `undefined` when none could be taken. */
3
- export type GpuSampler = () => Promise<GpuSnapshot | undefined>;
4
- /**
5
- * pid -> parent pid for `pids` and every ancestor up to init, read from
6
- * `<procRoot>/<pid>/status`. The sidecar shares the host pid namespace, so
7
- * that is the host's tree, and only the chains the GPU processes sit on are
8
- * read, never the whole host. A process that is gone by the time its entry is
9
- * read cuts its chain there: the pids below it keep their parents, the ones
10
- * above stay unknown, so `isDescendantOf` places the chain under no root.
11
- */
12
- export declare function readAncestry(pids: Iterable<number>, procRoot?: string): Promise<Map<number, number>>;
1
+ import { GpuDevice } from './gpuStats.js';
2
+ /** One reading of the host's GPUs, or `undefined` when none could be taken. */
3
+ export type GpuSampler = () => Promise<Map<string, GpuDevice> | undefined>;
13
4
  /**
14
5
  * A sampler that takes at most one reading per {@link SAMPLE_TTL_MS} and
15
6
  * hands the same one to every caller in that window. A reading still running
16
7
  * when its window ends keeps being handed out until it settles, so at most
17
- * one pair of `nvidia-smi` runs is in flight at a time. A host with no
18
- * visible GPU (no `nvidia-smi`, or no devices) yields no reading.
8
+ * one `nvidia-smi` run is in flight at a time. A host with no visible GPU (no
9
+ * `nvidia-smi`, or no devices) yields no reading.
19
10
  */
20
- export declare function createGpuSampler({ run, now, procRoot, }?: {
11
+ export declare function createGpuSampler({ run, now, }?: {
21
12
  run?: (args: string[], timeoutMs: number) => Promise<string | undefined>;
22
13
  now?: () => number;
23
- procRoot?: string;
24
14
  }): GpuSampler;
@@ -1,16 +1,13 @@
1
1
  import { execFile } from 'child_process';
2
- import { readFile } from 'fs/promises';
3
- import path from 'path';
4
- import { GPU_PMON_ARGS, GPU_QUERY_ARGS, MAX_ANCESTRY_DEPTH, parseGpuDevices, parseGpuProcesses, } from './gpuStats.js';
2
+ import { GPU_QUERY_ARGS, parseGpuDevices } from './gpuStats.js';
5
3
  const SAMPLE_TIMEOUT_MS = 10_000;
6
4
  /** Every container's stat is emitted on the same 5 s beat, so one reading
7
5
  * serves them all. */
8
6
  const SAMPLE_TTL_MS = 5_000;
9
7
  /**
10
- * Runs `nvidia-smi` with `args`. Its output is used whatever the exit code
11
- * (pmon exits non-zero where it is unsupported), unless it was killed
12
- * (timeout) or never started (no `nvidia-smi` mounted). The parsers decide
13
- * whether the output is a reading.
8
+ * Runs `nvidia-smi` with `args`. Its output is used whatever the exit code,
9
+ * unless it was killed (timeout) or never started (no `nvidia-smi` mounted).
10
+ * The parser decides whether the output is a reading.
14
11
  */
15
12
  function runNvidiaSmi(args, timeoutMs) {
16
13
  return new Promise((resolve) => {
@@ -23,60 +20,21 @@ function runNvidiaSmi(args, timeoutMs) {
23
20
  });
24
21
  });
25
22
  }
26
- async function readParentPid(pid, procRoot) {
27
- try {
28
- const status = await readFile(path.join(procRoot, String(pid), 'status'), 'utf8');
29
- const ppid = /^PPid:\s*(\d+)/m.exec(status)?.[1];
30
- return ppid === undefined ? undefined : Number(ppid);
31
- }
32
- catch {
33
- return undefined; // exited mid-walk, or not a readable process
34
- }
35
- }
36
- /**
37
- * pid -> parent pid for `pids` and every ancestor up to init, read from
38
- * `<procRoot>/<pid>/status`. The sidecar shares the host pid namespace, so
39
- * that is the host's tree, and only the chains the GPU processes sit on are
40
- * read, never the whole host. A process that is gone by the time its entry is
41
- * read cuts its chain there: the pids below it keep their parents, the ones
42
- * above stay unknown, so `isDescendantOf` places the chain under no root.
43
- */
44
- export async function readAncestry(pids, procRoot = '/proc') {
45
- const parents = new Map();
46
- for (const pid of new Set(pids)) {
47
- let current = pid;
48
- for (let depth = 0; depth < MAX_ANCESTRY_DEPTH && current > 1 && !parents.has(current); depth++) {
49
- const ppid = await readParentPid(current, procRoot);
50
- if (ppid === undefined)
51
- break;
52
- parents.set(current, ppid);
53
- current = ppid;
54
- }
55
- }
56
- return parents;
57
- }
58
23
  /**
59
24
  * A sampler that takes at most one reading per {@link SAMPLE_TTL_MS} and
60
25
  * hands the same one to every caller in that window. A reading still running
61
26
  * when its window ends keeps being handed out until it settles, so at most
62
- * one pair of `nvidia-smi` runs is in flight at a time. A host with no
63
- * visible GPU (no `nvidia-smi`, or no devices) yields no reading.
27
+ * one `nvidia-smi` run is in flight at a time. A host with no visible GPU (no
28
+ * `nvidia-smi`, or no devices) yields no reading.
64
29
  */
65
- export function createGpuSampler({ run = runNvidiaSmi, now = Date.now, procRoot = '/proc', } = {}) {
30
+ export function createGpuSampler({ run = runNvidiaSmi, now = Date.now, } = {}) {
66
31
  let cached;
67
32
  const sample = async () => {
68
- const [deviceOutput, pmonOutput] = await Promise.all([
69
- run(GPU_QUERY_ARGS, SAMPLE_TIMEOUT_MS),
70
- run(GPU_PMON_ARGS, SAMPLE_TIMEOUT_MS),
71
- ]);
72
- if (deviceOutput === undefined)
73
- return undefined;
74
- const devices = parseGpuDevices(deviceOutput);
75
- if (devices.size === 0)
33
+ const output = await run(GPU_QUERY_ARGS, SAMPLE_TIMEOUT_MS);
34
+ if (output === undefined)
76
35
  return undefined;
77
- const processes = parseGpuProcesses(pmonOutput ?? '', devices);
78
- const parents = await readAncestry(processes.map((process) => process.pid), procRoot);
79
- return { devices, processes, parents };
36
+ const devices = parseGpuDevices(output);
37
+ return devices.size === 0 ? undefined : devices;
80
38
  };
81
39
  return () => {
82
40
  const at = now();
@@ -7,64 +7,15 @@ export type GpuDevice = {
7
7
  memoryUsedMiB: number;
8
8
  memoryTotalMiB: number;
9
9
  };
10
- export type GpuProcess = {
11
- pid: number;
12
- gpuUuid: string;
13
- /** Framebuffer memory from `nvidia-smi pmon`, when the driver reports it. */
14
- memoryUsedMiB?: number;
15
- /** Per-process SM utilisation from `nvidia-smi pmon`, when the driver reports it. */
16
- smPercent?: number;
17
- };
18
- /** One host-wide reading: every GPU, every GPU process and where they sit. */
19
- export type GpuSnapshot = {
20
- /** Keyed by GPU uuid. */
21
- devices: Map<string, GpuDevice>;
22
- processes: GpuProcess[];
23
- /**
24
- * pid -> parent pid for every GPU process and its ancestors up to init,
25
- * and nothing else on the host. A pid missing from here has no known
26
- * parent, so it is under no container.
27
- */
28
- parents: Map<number, number>;
29
- };
30
10
  /** `nvidia-smi` arguments for the per-device figures, one CSV line per GPU. */
31
11
  export declare const GPU_QUERY_ARGS: string[];
32
- /**
33
- * `nvidia-smi` arguments for the per-process figures: `-s um` is utilisation
34
- * plus framebuffer memory, one row per (gpu, pid). pmon is best effort: it is
35
- * not supported on every device and its errors are dropped. Its `fb` column
36
- * comes from the same NVML accounting as `--query-compute-apps=used_memory`
37
- * (and is `-` exactly where that prints `[N/A]`, e.g. WSL and some vGPU), so
38
- * the latter is not run as well.
39
- */
40
- export declare const GPU_PMON_ARGS: string[];
41
12
  /** The devices from {@link GPU_QUERY_ARGS} output; `[N/A]` figures read as 0. */
42
13
  export declare function parseGpuDevices(output: string): Map<string, GpuDevice>;
43
14
  /**
44
- * The processes from {@link GPU_PMON_ARGS} output. pmon prints a header naming
45
- * its columns (`# gpu pid type sm mem enc dec ... fb ... command`), then one
46
- * row per GPU process. The column set varies with the driver (newer ones add
47
- * `jpg`, `ofa` and `ccpm`), so the columns are located by name. `-` stands for
48
- * an unsupported counter, and an idle GPU shows a row with `-` as the pid.
49
- * The gpu index is mapped to its uuid through `devices`.
50
- */
51
- export declare function parseGpuProcesses(output: string, devices: Map<string, GpuDevice>): GpuProcess[];
52
- export declare const MAX_ANCESTRY_DEPTH = 256;
53
- /** Whether `pid` is `rootPid` or one of its descendants. */
54
- export declare function isDescendantOf(parents: Map<number, number>, pid: number, rootPid: number): boolean;
55
- /**
56
- * The share of the snapshot that belongs to the container whose init process
57
- * is `rootPid`: every GPU process under it, grouped per device. Utilisation is
58
- * the sum of the container's per-process SM figures on a device, and memory
59
- * the sum of their framebuffer figures; when the driver reports none for that
60
- * device the whole-device figure stands in (exact on a device the container
61
- * has to itself, an overestimate on a shared one, never a false zero).
62
- *
63
- * A snapshot with no process at all is read the same way, with every device
64
- * standing in whole: pmon lists none not only on an idle host but wherever it
65
- * cannot resolve the pids the driver reports, which are the real host's. A
66
- * sidecar whose "host" pid namespace is itself a container's (podman inside a
67
- * docker container started without `--pid=host`) sees none of them, and the
68
- * job's GPU would otherwise read as a false zero for as long as it runs.
15
+ * The reading of every device in whole, which is what a job's GPU container
16
+ * is reported: exact on a device the container has to itself, an overestimate
17
+ * on a shared one. The container's own share (its GPU processes, mapped to it
18
+ * through the host pid namespace) is not attributed: that needs `--pid=host`,
19
+ * which a rootless or user-namespaced runtime cannot grant the sidecar.
69
20
  */
70
- export declare function attributeGpuStats(snapshot: GpuSnapshot, rootPid: number): GpuStat;
21
+ export declare function gpuStats(devices: Map<string, GpuDevice>): GpuStat;
@@ -3,16 +3,6 @@ export const GPU_QUERY_ARGS = [
3
3
  '--query-gpu=index,uuid,utilization.gpu,memory.used,memory.total',
4
4
  '--format=csv,noheader,nounits',
5
5
  ];
6
- /**
7
- * `nvidia-smi` arguments for the per-process figures: `-s um` is utilisation
8
- * plus framebuffer memory, one row per (gpu, pid). pmon is best effort: it is
9
- * not supported on every device and its errors are dropped. Its `fb` column
10
- * comes from the same NVML accounting as `--query-compute-apps=used_memory`
11
- * (and is `-` exactly where that prints `[N/A]`, e.g. WSL and some vGPU), so
12
- * the latter is not run as well.
13
- */
14
- export const GPU_PMON_ARGS = ['pmon', '-c', '1', '-s', 'um'];
15
- const isInt = (value) => /^\d+$/.test(value ?? '');
16
6
  function toNumber(value) {
17
7
  const parsed = Number(value?.trim());
18
8
  return Number.isFinite(parsed) ? parsed : 0;
@@ -35,120 +25,32 @@ export function parseGpuDevices(output) {
35
25
  }
36
26
  return devices;
37
27
  }
38
- /**
39
- * The processes from {@link GPU_PMON_ARGS} output. pmon prints a header naming
40
- * its columns (`# gpu pid type sm mem enc dec ... fb ... command`), then one
41
- * row per GPU process. The column set varies with the driver (newer ones add
42
- * `jpg`, `ofa` and `ccpm`), so the columns are located by name. `-` stands for
43
- * an unsupported counter, and an idle GPU shows a row with `-` as the pid.
44
- * The gpu index is mapped to its uuid through `devices`.
45
- */
46
- export function parseGpuProcesses(output, devices) {
47
- const uuidByIndex = new Map([...devices].map(([uuid, device]) => [device.index, uuid]));
48
- const processes = [];
49
- let columns;
50
- for (const line of output.split(/\r?\n/)) {
51
- const fields = line.trim().split(/\s+/);
52
- if (fields[0] === '#') {
53
- // The names header; the units header (`# Idx # C/G % ...`) is skipped.
54
- if (fields[1] === 'gpu')
55
- columns = fields.slice(1);
56
- continue;
57
- }
58
- if (!columns)
59
- continue;
60
- const names = columns;
61
- const column = (name) => fields[names.indexOf(name)];
62
- const pid = column('pid');
63
- const gpu = column('gpu');
64
- if (!isInt(pid) || !isInt(gpu))
65
- continue;
66
- const gpuUuid = uuidByIndex.get(Number(gpu));
67
- if (!gpuUuid)
68
- continue;
69
- const sm = column('sm');
70
- const fb = column('fb');
71
- processes.push({
72
- pid: Number(pid),
73
- gpuUuid,
74
- ...(isInt(fb) ? { memoryUsedMiB: Number(fb) } : {}),
75
- ...(isInt(sm) ? { smPercent: Number(sm) } : {}),
76
- });
77
- }
78
- return processes;
79
- }
80
- export const MAX_ANCESTRY_DEPTH = 256;
81
- /** Whether `pid` is `rootPid` or one of its descendants. */
82
- export function isDescendantOf(parents, pid, rootPid) {
83
- let current = pid;
84
- for (let depth = 0; depth < MAX_ANCESTRY_DEPTH && current !== undefined; depth++) {
85
- if (current === rootPid)
86
- return true;
87
- if (current <= 1)
88
- return false;
89
- current = parents.get(current);
90
- }
91
- return false;
92
- }
93
28
  const round = (value) => parseFloat(value.toFixed(2));
94
29
  const percent = (used, total) => round(total > 0 ? (used / total) * 100 : 0);
95
30
  /**
96
- * The share of the snapshot that belongs to the container whose init process
97
- * is `rootPid`: every GPU process under it, grouped per device. Utilisation is
98
- * the sum of the container's per-process SM figures on a device, and memory
99
- * the sum of their framebuffer figures; when the driver reports none for that
100
- * device the whole-device figure stands in (exact on a device the container
101
- * has to itself, an overestimate on a shared one, never a false zero).
102
- *
103
- * A snapshot with no process at all is read the same way, with every device
104
- * standing in whole: pmon lists none not only on an idle host but wherever it
105
- * cannot resolve the pids the driver reports, which are the real host's. A
106
- * sidecar whose "host" pid namespace is itself a container's (podman inside a
107
- * docker container started without `--pid=host`) sees none of them, and the
108
- * job's GPU would otherwise read as a false zero for as long as it runs.
31
+ * The reading of every device in whole, which is what a job's GPU container
32
+ * is reported: exact on a device the container has to itself, an overestimate
33
+ * on a shared one. The container's own share (its GPU processes, mapped to it
34
+ * through the host pid namespace) is not attributed: that needs `--pid=host`,
35
+ * which a rootless or user-namespaced runtime cannot grant the sidecar.
109
36
  */
110
- export function attributeGpuStats(snapshot, rootPid) {
111
- const perDevice = new Map();
112
- for (const process of snapshot.processes) {
113
- const device = snapshot.devices.get(process.gpuUuid);
114
- if (!device)
115
- continue;
116
- if (!isDescendantOf(snapshot.parents, process.pid, rootPid))
117
- continue;
118
- const share = perDevice.get(process.gpuUuid) ?? { device };
119
- if (process.memoryUsedMiB !== undefined) {
120
- share.memoryUsedMiB = (share.memoryUsedMiB ?? 0) + process.memoryUsedMiB;
121
- }
122
- if (process.smPercent !== undefined) {
123
- share.smPercent = (share.smPercent ?? 0) + process.smPercent;
124
- }
125
- perDevice.set(process.gpuUuid, share);
126
- }
127
- const attributed = snapshot.processes.length === 0
128
- ? [...snapshot.devices.values()].map((device) => ({ device }))
129
- : [...perDevice.values()];
130
- const shares = attributed
131
- .sort((a, b) => a.device.index - b.device.index)
132
- .map(({ device, memoryUsedMiB, smPercent }) => ({
133
- device,
134
- memoryUsedMiB: memoryUsedMiB ?? device.memoryUsedMiB,
135
- smPercent,
136
- }));
137
- const usedMiB = shares.reduce((sum, s) => sum + s.memoryUsedMiB, 0);
138
- const totalMiB = shares.reduce((sum, s) => sum + s.device.memoryTotalMiB, 0);
37
+ export function gpuStats(devices) {
38
+ const sorted = [...devices.values()].sort((a, b) => a.index - b.index);
39
+ const usedMiB = sorted.reduce((sum, d) => sum + d.memoryUsedMiB, 0);
40
+ const totalMiB = sorted.reduce((sum, d) => sum + d.memoryTotalMiB, 0);
139
41
  // Memory mirrors the container stat: usage in MiB, limit in GiB.
140
- const devices = shares.map(({ device, memoryUsedMiB, smPercent }) => ({
42
+ const perDevice = sorted.map((device) => ({
141
43
  index: device.index,
142
- gpu_percent: round(Math.min(100, smPercent ?? device.utilization)),
143
- memory_usage: round(memoryUsedMiB),
44
+ gpu_percent: round(Math.min(100, device.utilization)),
45
+ memory_usage: round(device.memoryUsedMiB),
144
46
  memory_limit: round(device.memoryTotalMiB / 1024),
145
- memory_percent: percent(memoryUsedMiB, device.memoryTotalMiB),
47
+ memory_percent: percent(device.memoryUsedMiB, device.memoryTotalMiB),
146
48
  }));
147
49
  return {
148
- gpu_percent: round(devices.reduce((sum, d) => sum + d.gpu_percent, 0)),
50
+ gpu_percent: round(perDevice.reduce((sum, d) => sum + d.gpu_percent, 0)),
149
51
  memory_usage: round(usedMiB),
150
52
  memory_limit: round(totalMiB / 1024),
151
53
  memory_percent: percent(usedMiB, totalMiB),
152
- devices,
54
+ devices: perDevice,
153
55
  };
154
56
  }
@@ -209,7 +209,6 @@ export class Provider {
209
209
  // GPU stats need the device; a node without GPUs (which may have no
210
210
  // GPU driver either) gives its sidecar none.
211
211
  ...(this.repository.getNodeInfo().gpus.devices.length > 0 ? { gpu: true } : {}),
212
- pid_mode: 'host',
213
212
  networks: { NOSANA_GATEWAY: {} },
214
213
  aliases: [name],
215
214
  env: {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@nosana/node",
3
- "version": "1.1.78-rc",
3
+ "version": "1.1.79-rc",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@nosana/node",
9
- "version": "1.1.78-rc",
9
+ "version": "1.1.79-rc",
10
10
  "license": "ISC",
11
11
  "workspaces": [
12
12
  "packages/*"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosana/node",
3
- "version": "1.1.78-rc",
3
+ "version": "1.1.79-rc",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "nosana-node": "./dist/src/index.js"