初始化
AiInferPool 通过静态工厂创建,不用 new。实现 AutoCloseable,用 try-with-resources。
每张图仍走 darra_session_infer_image(单图)。没有 N=100 的批张量 API。worker 的 unique 强制为 1,不会跟用户 Open 的驻留实例挤成一份。
options 为 null = workers=1、队列 64、InferOverflow.FAIL。maxWorkers 硬顶 8(0 = 1;合法 1..8)。queueCapacity 0 = 64;合法 1..4096。突发 100 张应 ≥ 100 或 overflow=BLOCK。
打开时选 Provider / 内部 ensure / fail-closed 与 会话初始化 相同。PLC:池必须在扫描周期外的线程里跑。
open / 带 options 的 open 不收激活码。submit / waitFor 永不收密码。
打开
AiInferPool.open(String containerPath, String preferProvider)
public static AiInferPool open(String containerPath, String preferProvider)
打开加密模型池。不收激活码。未激活走 activate。默认池选项。
参数:
containerPath(String) —.darmodel路径。空 / null =InternalExceptionpreferProvider(String) — 指名 Provider;null = 自动选
返回值:
AiInferPool— 新池(默认池选项)
示例:
try (AiInferPool pool = AiInferPool.open("model.darmodel", null)) {
long t = pool.submit(jpg, ImageDesc.auto());
String json = pool.waitFor(t);
}
AiInferPool.open(String containerPath, String preferProvider, InferPoolOptions options)
public static AiInferPool open(String containerPath,
String preferProvider,
InferPoolOptions options)
打开加密模型池。不收激活码。可传入池选项。
参数:
containerPath(String) —.darmodel路径(必填)preferProvider(String) — 指名 Provider;null = 自动选options(InferPoolOptions) — 池选项;null = Core 默认
返回值:
AiInferPool— 新池
示例:
InferPoolOptions opt = InferPoolOptions.empty().maxWorkers(2);
try (AiInferPool pool = AiInferPool.open("model.darmodel", null, opt)) {
long t = pool.submit(jpg, ImageDesc.auto());
String json = pool.waitFor(t);
}
AiInferPool.activate(String containerPath, String activationCode, String preferProvider)
public static AiInferPool activate(String containerPath,
String activationCode,
String preferProvider)
出厂 / 试用:UI 只要一次码。之后本机或本进程 open 免密。submit 永不收码。默认池选项。
activationCode 为 null / 空串 = InternalException(「activationCode 为空」)。空白串会送进 native。本重载不收池选项。
参数:
containerPath(String) —.darmodel路径(必填)activationCode(String) — 激活码 / 试用码(必填)preferProvider(String) — 指名 Provider;null = 自动选
返回值:
AiInferPool— 新池(默认池选项)
示例:
try (AiInferPool pool = AiInferPool.activate("model.darmodel", code, null)) {
long t = pool.submit(jpg, ImageDesc.auto());
String json = pool.waitFor(t);
}
AiInferPool.activate(String containerPath, String activationCode, String preferProvider, InferPoolOptions options)
public static AiInferPool activate(String containerPath,
String activationCode,
String preferProvider,
InferPoolOptions options)
出厂 / 试用开池,可传入池选项。空码约束同三参 activate。
参数:
containerPath(String) —.darmodel路径(必填)activationCode(String) — 激活码 / 试用码(必填)preferProvider(String) — 指名 Provider;null = 自动选options(InferPoolOptions) — 池选项;null = Core 默认
返回值:
AiInferPool— 新池
示例:
InferPoolOptions opt = InferPoolOptions.empty().maxWorkers(2);
try (AiInferPool pool = AiInferPool.activate("model.darmodel", code, null, opt)) {
long t = pool.submit(jpg, ImageDesc.auto());
String json = pool.waitFor(t);
}
AiInferPool.openWithKey(String containerPath, String keyPath, String preferProvider)
public static AiInferPool openWithKey(String containerPath,
String keyPath,
String preferProvider)
旧双文件 .darmkey。新 DARB1 不要用。默认池选项。keyPath 空 / null = InternalException。
参数:
containerPath(String) —.darmodel路径(必填)keyPath(String) —.darmkey路径(必填)preferProvider(String) — 指名 Provider;null = 自动选
返回值:
AiInferPool— 新池(默认池选项)
AiInferPool.openWithKey(String containerPath, String keyPath, String preferProvider, InferPoolOptions options)
public static AiInferPool openWithKey(String containerPath,
String keyPath,
String preferProvider,
InferPoolOptions options)
旧双文件 .darmkey 开池,可传入池选项。keyPath 空 / null = InternalException。
参数:
containerPath(String) —.darmodel路径(必填)keyPath(String) —.darmkey路径(必填)preferProvider(String) — 指名 Provider;null = 自动选options(InferPoolOptions) — 池选项;null = Core 默认
返回值:
AiInferPool— 新池
AiInferPool.openPlain(String modelPath, String preferProvider, InferPoolOptions options)
public static AiInferPool openPlain(String modelPath,
String preferProvider,
InferPoolOptions options)
打开明文模型池。本绑定只有这一份三参重载,没有两参省略 options 的工厂。options 为 null = workers=1、队列 64、FAIL。
参数:
modelPath(String) — 明文模型路径(.onnx/.pdmodel/ 含二者的目录)。空 / null =InternalExceptionpreferProvider(String) — 指名 Provider;null = 自动选options(InferPoolOptions) — 池选项;null = Core 默认
返回值:
AiInferPool— 新池
.pt / .pth → UnsupportedPayloadException。
示例:
InferPoolOptions opt = InferPoolOptions.empty()
.maxWorkers(2)
.queueCapacity(128)
.overflow(InferOverflow.FAIL)
.worker(SessionOptions.empty().gpuDevice(0))
.weight(100);
try (AiInferPool pool = AiInferPool.openPlain("yolov8n.onnx", "onnx-cuda", opt)) {
long t = pool.submit(jpg, ImageDesc.auto());
String json = pool.waitFor(t);
}
一块 GPU 不要按图片数开会话。maxWorkers 硬顶 8。worker 选项里的 Unique 会被池强制为 true。