1/* @ajax/mesh-occupancy: co-residency of resident kernels (CUDA; mesh-host
2 * backend.rs co_resident, room). Every program's nodes must be on the GPU at
3 * once, forever, so a load is refused unless all of them fit. Three rules:
4 * - each kernel: nodes <= per_sm x SMs; all: blocks <= blocks_per_sm x SMs;
5 * - the occupancy shares sum(nodes / (per_sm x SMs)) <= 1;
6 * - fragmentation: a node that needs a whole SM (per_sm == 1) fits only on an
7 * SM no other block touches, so the whole-SM nodes plus min(SMs, the other
8 * blocks) must not exceed the SMs. */
9#ifndef MESH_OCCUPANCY_H
10#define MESH_OCCUPANCY_H
1112#include <stdbool.h>
13#include <stddef.h>
14#include <stdint.h>
1516/* One kernel: its nodes and the resident blocks of its shape per SM. */
17typedef struct {
18 uint32_t nodes;
19 uint32_t per_sm;
20} mesh_occ_kernel;
2122/* False with *err (the Rust's message) when the kernels don't fit together. */
23bool mesh_co_resident(const mesh_occ_kernel *k, size_t n, uint32_t sms, uint32_t blocks_per_sm, char **err);
24/* The most nodes (at most max) of a kernel of per_sm that fit beside others; 0: none. */
25uint32_t mesh_occ_room(const mesh_occ_kernel *others, size_t n, uint32_t per_sm, uint32_t max, uint32_t sms, uint32_t blocks_per_sm);
2627#endif