| """Load resample-poly natively on hosts without a published variant. |
| |
| import load_local |
| rp = load_local.load() |
| """ |
| import os |
| import sys |
| import types |
|
|
| _cached = None |
|
|
|
|
| def load(verbose=False): |
| """Return the resample_poly module, JIT-built from the local source.""" |
| global _cached |
| if _cached is not None: |
| return _cached |
| from torch.utils.cpp_extension import load as _jit |
|
|
| root = os.path.dirname(os.path.abspath(__file__)) |
| cflags = ["/O2"] if os.name == "nt" else ["-O3"] |
| ext = _jit(name="resample_poly_ext", |
| sources=[os.path.join(root, "local_bind.cpp"), |
| os.path.join(root, "resample_csrc", "resample.cpp")], |
| extra_include_paths=[os.path.join(root, "torch-ext")], |
| extra_cflags=cflags, |
| verbose=verbose) |
| ops_mod = types.ModuleType("resample_poly._ops") |
| ops_mod.ops = type("_Ops", (), { |
| "rp_resample": staticmethod(ext.rp_resample), |
| })() |
| sys.modules["resample_poly._ops"] = ops_mod |
| sys.path.insert(0, os.path.join(root, "torch-ext")) |
| import resample_poly |
| _cached = resample_poly |
| return resample_poly |
|
|