hawk.artifact.build_bundle

Contents

hawk.artifact.build_bundle#

hawk.artifact.build_bundle(kernels, directory, *, mode='float64', targets=('cuda', 'host'), kind=None, layout_sizes_override=None, defines=(), cache_dir=None, device_arch='', name=None, derivative=None, host_profile='', opt_level='', literal_table=False, embedded_profile=None, emit_form=None, linalg_form=None, wide_form=None, launch_bounds=None)[source]#

Build every kernel into directory and write ONE manifest.json over them. An emit_form/linalg_form/wide_form/launch_bounds left unset is the ambient hawk.emit.policy.using() value (the default: "auto", no bound); an explicit argument wins. emit_form is how a product, dot, sum or norm is spelled (hawk.emit.policy): "auto" unrolls a site of at most 16 elements and writes a longer one as a loop, "static" unrolls every site, "rolled" writes every site as a loop, the fast-compile mode (the compiler does no per-element work). linalg_form is how per-lane linear algebra is worked: "auto" keeps one thread per matrix up to n = 32 and uses a team of threads per matrix above it, "team" uses a team at every size, "thread" refuses a matrix above 32 by name (hawk.ir.team). wide_form is where a per-lane value wider than a thread’s registers lives: "auto" builds a kernel as a warp per lane when every target is a device and the kernel has a rule in that form (hawk.ir.lane, folds of 128 elements or more), else places the value (hawk.ir.wide) – a bundle with a host target keeps the placed form, as the host has no warp; "thread" keeps every value in the lane’s registers and local memory (the text before the pass); "team" asks for the warp form (device targets only). launch_bounds=(threads, blocks_per_sm) compiles every device kernel with __launch_bounds__(threads, blocks_per_sm) and records launch.block = threads in the sidecar, so a launch runs that block size (threads a multiple of 32, threads * blocks_per_sm at most 2048; the values do not change). Every member must agree on the execution axis (a manifest-level, not per-entry, declaration) — a set that doesn’t agree is two bundles.

This is the DEPLOYMENT UNIT: publishing is content-addressed (see the module docstring) — a repeat build of an already-published definition recompiles nothing, copying files into a different directory if asked, so the returned Bundle always names a directory that genuinely holds the unit.

derivative names each derivative kernel’s primal, per kernel: {kernel_name: primal_name}, or leave it (None) to use a hawk.diff.vjp()/jvp() kernel’s own recorded primal. A primal outside this bundle is named by {kernel_name: (primal_name, primal_unit_digest)} via its Bundle.digest — needed when the primal and its scattering VJP can’t share one manifest.

host_profile picks the host code-gen profile (hawk.compile.toolchain.HOST_PROFILES): "native-vector-math" (default on x86-64 with a GCC host compiler, and on arm64) or "native" (libm bit-identity) for a bundle built on the machine that runs it, "portable" for one that’s prebuilt and shipped. Empty means $HAWK_HOST_PROFILE, else hawk.compile.toolchain.default_host_profile().

opt_level picks the optimisation level (hawk.compile.toolchain.OPT_LEVELS: "O0"..``”O3”), the same way for every target this bundle builds: ``-O<n> on the host build and on an AOT nvcc device build (nvcc’s own -O<n> plus -Xptxas -O<n>); NVRTC device compiles always optimise and ignore it. Empty means $HAWK_OPT_LEVEL, else hawk.compile.toolchain.DEFAULT_OPT_LEVEL ("O3").

literal_table (default False) makes the device source read its double literals from one __constant__ table per translation unit instead of as operand immediates: the same bits, fewer constant-move instructions on architectures that issue a move pair per literal (sm_90), unchanged on the others. Off, the device code is byte-identical to a build without the option. A float32 build ignores it, and the host build is not affected.

"c" in targets adds each kernel’s standalone MISRA C unit (hawk.embedded: <name>.c, <name>.h, <name>.embedded.json, audited and toolchain-checked) under embedded_profile (hawk.embedded.EmbeddedProfile when None). It never enters the manifest or a sidecar: those describe the native targets only, and a unit built for ("c",) alone writes neither (Bundle.manifest is None).

Return type:

Bundle

Parameters:
  • mode (str)

  • device_arch (str)

  • name (str | None)

  • derivative (Mapping[str, str] | None)

  • host_profile (str)

  • opt_level (str)

  • literal_table (bool)

  • emit_form (str | None)

  • linalg_form (str | None)

  • wide_form (str | None)

  • launch_bounds (tuple[int, int] | None)