from . import _backend as _backend
if _backend.npu_enabled():
from npu_patch.api import Buffer as Buffer
from npu_patch.planning import MoonEPCommPlan as MoonEPCommPlan
from npu_patch.shmem_runtime import ShmemRuntime as ShmemRuntime
else:
from .api import Buffer, MoonEPCommPlan as MoonEPCommPlan
def init_shmem(group=None, **kwargs):
"""Initialize the shmem symmetric heap on NPU (no-op on GPU).
Required on Ascend before the first dispatch/combine/prefetch/reduce_grad,
after every ``Buffer`` has been constructed. On GPU this is a no-op so
single-file test/benchmark code can call it unconditionally.
"""
if not _backend.npu_enabled():
return
from npu_patch.shmem_runtime import ShmemRuntime
ShmemRuntime.init_with_buffer(group=group, **kwargs)
__all__ = [
"Buffer",
"MoonEPCommPlan",
"init_shmem",
]