File size: 667 Bytes
a064299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""Taichi lifecycle helpers for HF ZeroGPU (init on demand, release before render)."""

from __future__ import annotations

import os

import taichi as ti

_TAICHI_READY = False


def hf_space_mode() -> bool:
    return os.environ.get("ENDOGSIM_HF_SPACE") == "1"


def ensure_taichi_runtime() -> None:
    global _TAICHI_READY
    if _TAICHI_READY:
        return
    ti_mem = 0.05 if hf_space_mode() else 0.1
    ti.init(arch=ti.cuda, device_memory_fraction=ti_mem)
    _TAICHI_READY = True


def release_taichi_runtime() -> None:
    global _TAICHI_READY
    if not _TAICHI_READY:
        return
    if hf_space_mode():
        ti.reset()
    _TAICHI_READY = False