龙芯加速计算平台 v0.1.0 用户手册

1. 简介

龙芯加速计算平台(Loongson Accelerated Computing Platform,LACm)是为龙芯通用 GPU 推出的全栈加速解决方案,旨在为高性能计算、人工智能和科学计算提供高效的 GPU 加速支持。该平台提供了从硬件抽象、驱动支持、计算库及深度学习框架适配的全套软件栈,核心组件包括运行时环境、专用编译器、高性能算子库和推理引擎等。

LACm v0.1.0 兼容 OpenCL 3.0 规范、CUDA 5.0 计算能力规范及 CUDA API 10.0 规范。

2. 文档概述

本文档旨在为用户提供 LACm 软件栈的使用指南与参考资料。文档主要内容包括:

  • LACm 软件栈的功能特性和支持的数学库说明;
  • LACm 软件栈的安装概览与依赖说明;
  • 安装 LACm 软件栈后的 ONNX Runtime 示例;
  • 龙芯加速计算推理引擎 LACInfer 示例。

通过本手册,用户能够快速了解 LACm 软件栈的能力,掌握其配置与运行方法,从而在 LoongArch 平台上高效开展 AI 推理与异构计算相关工作。

3. 功能特性

LACm 软件栈包含下列四类核心功能特性:

  • 支持 CUDA 核心功能:设备/上下文管理、显存及统一内存操作、核函数执行、多流与事件、错误处理。
  • 支持 OpenCL 3.0:平台与执行模型、内存层次、数据/任务并行、同步机制、错误与性能分析。
  • 支持张量加速,涵盖 i8/u8 类型矩阵运算。
  • 支持龙芯加速计算推理引擎 LACInfer。

4. 安装概览

4.1. 安装组件

本次发布提供以下组件:

组件 内容
LACm 软件栈 龙芯自研 GPU 算力软件栈驱动、编译器、加速库(现版本仅包括 blas 和 dnn 库)。
深度学习框架、推理框架 ONNX Runtime 二进制和 whl 包
示例脚本 常用模型推理脚本

4.2. 系统要求

操作系统 Loongnix-desktop 20.* Loongnix-desktop 25.*
内核版本 4.19.0 6.6.52
loonggpu 驱动版本 >=1.0.2-lnd.2 >=1.0.2-lnd25.1
loonggpu 固件版本 >=1.0.2-lnd.2 >=1.0.2-lnd25.1
  • 权限:安装需 root 权限或具备 sudo 权限
  • 存储空间:至少需要 3GB 空间
  • 内存空间:至少 8GB RAM
  • 显存要求:大于等于 2GB

4.3. 安装方式

LACm 软件栈提供以下安装方式:

  • 软件包安装:通过预编译的 .deb 包快速部署

4.4. 开始之前

4.4.1 确认 GPU 驱动和固件版本

您可以执行如下命令查看 loonggpu 驱动和固件版本号,如果大于等于文档 4.2 章节中要求 loonggpu 驱动版本和固件版本则符合要求(以下以 loongnix25 操作系统作为示例,loongnix20 操作系统类似)。

$ dpkg -l | grep loonggpu-kernel-dkms
ii  loonggpu-kernel-dkms       1.0.2-lnd25.1   loong64   LOONGGPU binary kernel module DKMS source

$ dpkg -l | grep firmware-loongson-graphics
ii  firmware-loongson-graphics  1.0.2-lnd25.1   loong64   LOONGGPU driver firmware

$

如果小于该版本号,您可以选择从 https://www.loongnix.cn/zh/graph/loonggpu/ 网站下载对应操作系统上最新的 loonggpu 驱动本地源进行安装,安装方式如下:

# loongnix20 系统安装
# 参考 Loongnix20 本地源下载安装
$ sudo dpkg -i loonggpu-repo-loongnix20-local_{v.r.m}_loongarch64.deb
$ sudo cp /var/loonggpu-repo-loongnix20-local/loonggpu-*-keyring.gpg /usr/share/keyrings/
$ sudo apt-get update
$ sudo apt-get -y install loonggpu-driver

# loongnix25 系统安装
# 参考 Loongnix25 本地源下载安装
$ sudo dpkg -i loonggpu-repo-loongnix25-local_{v.r.m}_loongarch64.deb
$ sudo apt-get update
$ sudo apt-get -y install loonggpu-driver

4.4.2. 确认 GPU 驱动已安装

您可以执行 lspci 命令查看龙芯 GPU 信息,执行信息中存在 "Kernel driver in use: loonggpu" 说明 GPU 驱动正确安装。

$ lspci -s 00:06.0 -vvv
    ......
    Kernel driver in use: loonggpu
$

4.4.3. 确认显存大小分配正确

在确认龙芯 GPU 驱动已安装的前提下,继续执行 lspci 命令查看显存地址分配情况。运行 LACm 算力软件栈建议分配 2G 显存。

例如,您得到以下输出内容,则说明显存分配 2G。

$ lspci -s 00:06.0 -vvv
00:06.0 Multimedia video controller: Loongson Technology LLC Device 7a35 (rev 10)
    Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop+ ParErr- Stepping- SERR- FastB2B- DisINTx-
    Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
    Latency: 0
    Interrupt: pin A routed to IRQ 102
    NUMA node: 0
    Region 0: Memory at 408125e000 (64-bit, non-prefetchable) [size=256]
    Region 2: Memory at 4000000000 (64-bit, non-prefetchable) [size=2G]
    Region 4: Memory at 4081200000 (64-bit, non-prefetchable) [size=64K]
    Kernel driver in use: loonggpu
$

4.5. 安装步骤概览

4.5.1. 获取安装包

您可以从 https://www.loongnix.cn/zh/compute/loongacm/loongacm-download/ 网站下载对应操作系统适配的 LACm 软件栈压缩包(loongac-{v.r.m}-{os-version}.tgz)。

4.5.2. 安装 LACm 软件栈

您可以按照如下步骤安装 LACm 软件栈。

tar -xf loongac-{v.r.m}-{os-version}.tgz
cd loongac-{v.r.m}-{os-version}
sudo apt install ./*.deb

4.5.3. 配置用户组

您需要将您想要可以直接执行 GPU 程序的用户加入到 render 和 video 组中。

sudo usermod -a -G render,video $LOGNAME   # 将当前用户加入 render 和 video 组中,其中 $LOGNAME 可以换成自己想要添加的用户名,配置后需重新注销登录生效。

4.5.4. 验证安装

您可以执行 /opt/lacm/bin/clinfo 验证 LACm 软件栈是否安装成功了,假如出现如下示例即可证明 LACm 软件栈安装成功。

$ /opt/lacm/bin/clinfo
Number of platforms:                               1
  Platform Profile:                                FULL_PROFILE
  Platform Version:                                OpenCL 3.0 LS-APP (3581.0)
  Platform Name:                                   LS Accelerated Parallel Processing
  Platform Vendor:                                 Loongson Technology
  Platform Extensions:                              cl_khr_icd cl_ls_event_callback

  Platform Name:                                   LS Accelerated Parallel Processing
Number of devices:                                 1
  Device Type:                                     CL_DEVICE_TYPE_GPU
  Vendor ID:                                       14h
  Board name:                                      LOONGSON LoongGPU (TM) LG200
  Device Topology:                                 PCI[ B#0, D#6, F#0 ]
  ......

4.5.5. 安装后目录结构

LACm 软件栈默认安装在 /opt/lacm-{v.r.m} 下,/opt/lacm 为 /opt/lacm-{v.r.m} 软链接,您可以通过 update-alternatives --list lacm 命令查询指向的 LACm 软件栈版本。

/opt/lacm-{v.r.m}
├── bin
├── include
├── lggpu
├── lib
├── llvm -> ./lib/llvm
└── share

5. 使用说明

5.1. 注意事项

使用 LACm 算力软件栈需要执行 sudo init 3 进入命令行模式(现有算力软件栈不支持桌面图形和算力软件栈并行使用),或者可以通过远程 ssh -X 连接 2k3000 机器使用本地图形模式。

5.2. 帮助和问题报告

您使用过程中有任何问题均可发送邮件至 service@loongnix.cn 进行咨询。

6. 使用示例

LACm 软件栈支持以下两种 ONNX 模型推理方式,用户可按需选择:

  • LACInfer 接口:直接调用 LACInfer 推理引擎的 Python 或 C++ 接口编写推理代码,可精细控制模型加载、编译与量化(见 6.1 节);
  • ONNX Runtime 后端:通过 ONNX Runtime 的 LACInfer 执行提供器(LACInferExecutionProvider)进行推理,适合已有 ONNX Runtime 应用无缝接入 GPU 加速(见 6.2 节)。

6.1. LACInfer 示例

本章节演示如何在 LACm 算力软件栈安装完成后,使用 LACInfer 推理引擎的 Python 接口进行模型推理,涵盖模型加载、量化、编译、推理与后处理的完整流程,以及 INT8 量化与编译后模型(.lir)的生成与复用。更详细的接口说明与算子支持范围,请参考《LACInfer API 手册》以及《LACInfer 算子支持列表》。

为便于快速体验 lacinfer 的推理能力,lacinfer-model-zoo 内置了从 YOLOv5、YOLOv6、YOLOv7 到 YOLO26 的完整 Python 示例,覆盖 YOLO 全系列。您既可以整体镜像,也可以只取所需模型,命令如下:

lftp https://repos.loongson.cn/loongacm/
mirror lacinfer-model-zoo

6.1.1. Python 实现伪代码

import lacinfer

# 1. 解析 ONNX 模型
model = lacinfer.parse_onnx("path/to/model.onnx")

# 2. 查询输入名称与形状
input_name = model.get_parameter_names()[0]
input_shape = model.get_parameter_shapes()[input_name].lens()

# 3. 编译到 GPU
model.compile(t=lacinfer.get_target("gpu"))

# 4. 准备输入并执行推理
result = model.run({input_name: input_img})

# 5. 后处理输出
outputs = [np.array(out) for out in result]

6.1.2. YOLOv8 模型的 Python 实现示例

import cv2
import numpy as np
import argparse
import lacinfer


def softmax(x, axis):
    x_max = np.amax(x, axis=axis, keepdims=True)
    e_x = np.exp(x - x_max)
    return e_x / np.sum(e_x, axis=axis, keepdims=True)


def dfl(position):
    n, c, h, w = position.shape
    p_num = 4
    mc = c // p_num
    y = position.reshape(n, p_num, mc, h, w)
    y = softmax(y, axis=2)
    acc = np.arange(mc, dtype=np.float32).reshape(1, 1, mc, 1, 1)
    y = (y * acc).sum(axis=2)
    return y


def box_process(position, input_size):
    input_w, input_h = input_size
    grid_h, grid_w = position.shape[2:4]
    col, row = np.meshgrid(np.arange(0, grid_w), np.arange(0, grid_h))
    col = col.reshape(1, 1, grid_h, grid_w)
    row = row.reshape(1, 1, grid_h, grid_w)
    grid = np.concatenate((col, row), axis=1)

    stride = np.array([input_w / grid_w, input_h / grid_h], dtype=np.float32).reshape(1, 2, 1, 1)

    position = dfl(position)
    box_xy = grid + 0.5 - position[:, 0:2, :, :]
    box_xy2 = grid + 0.5 + position[:, 2:4, :, :]
    xyxy = np.concatenate((box_xy * stride, box_xy2 * stride), axis=1)

    return xyxy


def xywh2xyxy(boxes_xywh):
    boxes = boxes_xywh.copy()
    boxes[:, 0] = boxes_xywh[:, 0] - boxes_xywh[:, 2] / 2.0
    boxes[:, 1] = boxes_xywh[:, 1] - boxes_xywh[:, 3] / 2.0
    boxes[:, 2] = boxes_xywh[:, 0] + boxes_xywh[:, 2] / 2.0
    boxes[:, 3] = boxes_xywh[:, 1] + boxes_xywh[:, 3] / 2.0
    return boxes


def nms_boxes(boxes, scores, nms_thresh):
    x1 = boxes[:, 0]
    y1 = boxes[:, 1]
    x2 = boxes[:, 2]
    y2 = boxes[:, 3]

    areas = (x2 - x1) * (y2 - y1)
    order = scores.argsort()[::-1]

    keep = []
    while order.size > 0:
        i = order[0]
        keep.append(i)

        xx1 = np.maximum(x1[i], x1[order[1:]])
        yy1 = np.maximum(y1[i], y1[order[1:]])
        xx2 = np.minimum(x2[i], x2[order[1:]])
        yy2 = np.minimum(y2[i], y2[order[1:]])

        w = np.maximum(0.0, xx2 - xx1 + 1e-5)
        h = np.maximum(0.0, yy2 - yy1 + 1e-5)
        inter = w * h

        union = areas[i] + areas[order[1:]] - inter
        iou = inter / np.maximum(union, 1e-12)

        inds = np.where(iou <= nms_thresh)[0]
        order = order[inds + 1]

    return np.array(keep, dtype=np.int64)


class YOLOv8:
    def __init__(self, cocopath, modelpath, obj_thres=0.25, iou_thres=0.45):
        self.objectThreshold = obj_thres
        self.nmsThreshold = iou_thres
        self.classNames = list(map(lambda x: x.strip(), open(cocopath, 'r').readlines()))

        # 解析 ONNX 模型
        self.model = lacinfer.parse_onnx(modelpath)

        # 查询输入名称与形状
        self.inputName = self.model.get_parameter_names()[0]
        inputShape = self.model.get_parameter_shapes()[self.inputName].lens()
        self.inputHeight = int(inputShape[2])
        self.inputWidth = int(inputShape[3])
        print("inputName:{0} \ninputShape:{1}".format(self.inputName, inputShape))

        # 编译到 GPU
        self.model.compile(t=lacinfer.get_target("gpu"))

    def detect(self, image):
        # 输入图片预处理
        input_img = self.prepare_input(image)

        # 执行推理
        print("running...")
        result = self.model.run({self.inputName: input_img})

        # 模型输出后处理
        boxes, scores, class_ids = self.process_output(result)

        # 坐标还原到原图
        if boxes is not None:
            boxes[:, [0, 2]] -= self.pad_left
            boxes[:, [1, 3]] -= self.pad_top
            boxes[:, [0, 2]] /= self.scale_ratio
            boxes[:, [1, 3]] /= self.scale_ratio
            boxes[:, [0, 2]] = np.clip(boxes[:, [0, 2]], 0, self.img_width)
            boxes[:, [1, 3]] = np.clip(boxes[:, [1, 3]], 0, self.img_height)

        return boxes, scores, class_ids

    def prepare_input(self, image):
        self.img_height, self.img_width = image.shape[:2]
        self.scale_ratio = min(self.inputWidth / self.img_width, self.inputHeight / self.img_height)
        new_w = int(self.img_width * self.scale_ratio)
        new_h = int(self.img_height * self.scale_ratio)
        resized = cv2.resize(image, (new_w, new_h), interpolation=cv2.INTER_LINEAR)
        canvas = np.full((self.inputHeight, self.inputWidth, 3), 0, dtype=np.uint8)
        self.pad_top = (self.inputHeight - new_h) // 2
        self.pad_left = (self.inputWidth - new_w) // 2
        canvas[self.pad_top:self.pad_top+new_h, self.pad_left:self.pad_left+new_w] = resized
        input_img = cv2.cvtColor(canvas, cv2.COLOR_BGR2RGB)
        input_img = input_img.transpose(2, 0, 1)
        input_img = np.expand_dims(input_img, 0)
        input_img = np.ascontiguousarray(input_img)
        input_img = input_img.astype(np.float32)
        input_img = input_img / 255.0

        return input_img

    def process_output(self, outputs):
        outputs = [np.array(out) for out in outputs]

        boxes_list, scores_list = [], []
        input_size = (self.inputWidth, self.inputHeight)

        if len(outputs) >= 6 and outputs[0].ndim == 4:
            default_branch = 3
            pair_per_branch = len(outputs) // default_branch

            for i in range(default_branch):
                boxes_list.append(box_process(outputs[pair_per_branch * i], input_size))
                cls_output = outputs[pair_per_branch * i + 1]

                grid_h, grid_w = cls_output.shape[2:4]
                num_classes = cls_output.shape[1]
                scores_flat = cls_output.transpose(0, 2, 3, 1).reshape(-1, num_classes)
                scores_list.append(scores_flat)

            def flatten_boxes(b):
                return b.transpose(0, 2, 3, 1).reshape(-1, 4)

            boxes = np.concatenate([flatten_boxes(v) for v in boxes_list])
            scores_all = np.concatenate(scores_list)
            classes = scores_all.argmax(axis=1)
            max_scores = scores_all.max(axis=1)

            keep_mask = max_scores >= self.objectThreshold
            boxes = boxes[keep_mask]
            classes = classes[keep_mask]
            max_scores = max_scores[keep_mask]
        else:
            pred = np.squeeze(outputs[0])
            if pred.ndim != 2:
                raise ValueError(f"Unexpected output shape: {outputs[0].shape}")
            if pred.shape[0] < pred.shape[1]:
                pred = pred.T

            boxes = xywh2xyxy(pred[:, :4])
            class_scores = pred[:, 4:]
            classes = class_scores.argmax(axis=1)
            max_scores = class_scores[np.arange(class_scores.shape[0]), classes]

            keep_mask = max_scores >= self.objectThreshold
            boxes = boxes[keep_mask]
            classes = classes[keep_mask]
            max_scores = max_scores[keep_mask]

        if len(boxes) == 0:
            return None, None, None

        # 逐类NMS
        nboxes, nclasses, nscores = [], [], []
        for c in set(classes.tolist()):
            inds = np.where(classes == c)
            b = boxes[inds]
            cls = classes[inds]
            s = max_scores[inds]
            keep = nms_boxes(b, s, self.nmsThreshold)

            if keep.size > 0:
                nboxes.append(b[keep])
                nclasses.append(cls[keep])
                nscores.append(s[keep])

        if not nboxes:
            return None, None, None

        boxes = np.concatenate(nboxes)
        classes = np.concatenate(nclasses)
        scores = np.concatenate(nscores)

        return boxes, scores, classes

    def draw_detections(self, image, boxes, scores, class_ids):
        for box, score, cl in zip(boxes, scores, class_ids):
            x1, y1, x2, y2 = [int(_b) for _b in box]
            label = self.classNames[cl] if cl < len(self.classNames) else str(cl)
            cv2.rectangle(image, (x1, y1), (x2, y2), (255, 0, 0), 2)
            cv2.putText(image, '{0} {1:.2f}'.format(label, score),
                        (x1, y1 - 6), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 2)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--imgPath', type=str, default='../images/bus.jpg', help="image path")
    parser.add_argument('--cocoClassPath', type=str, default='../models/coco.names', help="coco classes path")
    parser.add_argument('--staticModelPath', type=str, default='../models/f32_model/yolov8n.onnx', help="static onnx filepath")
    parser.add_argument('--objectThreshold', default=0.25, type=float, help='class confidence')
    parser.add_argument('--nmsThreshold', default=0.45, type=float, help='nms iou thresh')
    parser.add_argument('--resPath', type=str, default='./Result.jpg', help="result path")
    args = parser.parse_args()

    detector = YOLOv8(args.cocoClassPath, args.staticModelPath,
                      obj_thres=args.objectThreshold, iou_thres=args.nmsThreshold)
    srcimg = cv2.imread(args.imgPath, 1)
    boxes, scores, class_ids = detector.detect(srcimg)

    if boxes is not None:
        dstimg = srcimg.copy()
        detector.draw_detections(dstimg, boxes, scores, class_ids)
        cv2.imwrite(args.resPath, dstimg)
        print("Success to save result", args.resPath)
    else:
        print("Nothing detected!")

运行命令如下:

python3 yolov8_infer_lacinfer.py --imgPath bus.jpg --staticModelPath yolov8n.onnx --cocoClassPath coco.names

执行成功后,脚本将检测结果绘制到图片并保存当前路径下默认 Result.jpg 文件。

6.1.3. INT8 量化与编译模型示例

$ cat yolov8_quant_lacinfer.py

import cv2
import numpy as np
import os
import lacinfer

# 解析 ONNX 模型
model = lacinfer.parse_onnx("path/to/model.onnx")
input_name = model.get_parameter_names()[0]

# 或 INT8 量化(需校准数据)
caldata = []
images = []
for image_file in os.listdir(calib_dir):
    srcimg = cv2.imread(os.path.join(calib_dir, image_file), 1)
    input_img = preprocess(srcimg)          # 与推理一致的前处理
    images.append(input_img)
caldata = [{input_name: lacinfer.argument(img)} for img in images]
lacinfer.quantize_int8(model, lacinfer.get_target("gpu"), caldata)

# 编译并保存编译模型
model.compile(t=lacinfer.get_target("gpu"))
lacinfer.save(model, "model-compiled.lir")

# 复用编译模型进行推理
model = lacinfer.load("model-compiled.lir", format="msgpack")
result = model.run({input_name: input_img})

也可使用 lacinfer-model-zoo 仓库提供的脚本进行 INT8 量化,只需通过 --action 与 --saveLirs 指定动作:

python yolov8_infer_lacinfer.py --staticModelPath ../models/f32_model/yolov8n.onnx --action quant-int8 --calibrationPath ../images --saveLirs

6.2. ONNX Runtime 示例

本章节演示如何在 LACm 算力软件栈安装完成后,使用 ONNX Runtime (ORT) 进行模型推理。

6.2.1 安装 ONNX Runtime

6.2.1.1. 通过 pip 安装(Python 环境)

适用于需要在 Python 环境中运行 ONNX 模型的用户。

  • loongnix20 系统安装 LoongGPU 版本 onnxruntime(需 Python ≥ 3.7)

    pip3 install onnxruntime_lacm-1.21.0+lacm.0.1.0.lnd.3-cp37-cp37m-linux_loongarch64.whl
    
  • loongnix25 系统安装 LoongGPU 版本 onnxruntime(需 Python ≥ 3.13),且需要在虚拟环境中安装。

    $ sudo apt install python3.13-venv
    $ python3 -m venv myvenv
    $ source myvenv/bin/activate
    pip3 install onnxruntime_lacm-1.21.0+lacm.0.1.0.lnd25.2-cp313-cp313-linux_loongarch64.whl
    

安装完成后,可在 Python 中验证:

$ cat lacm.py
import onnxruntime as ort
print("ONNX Runtime version:", ort.__version__)
print("Available providers:", ort.get_available_providers())
$
$ python3 lacm.py
ONNX Runtime version: 1.21.0
Available providers: ['LACInferExecutionProvider', 'CPUExecutionProvider']
$

执行该 Python 代码,若输出如下则说明安装成功,并已启动 LACm 的 GPU 加速能力。

6.2.1.2. 通过 tgz 压缩包安装(C/C++ 环境)

适用于需要在 C/C++ 应用中调用 ONNX Runtime 库的用户。

tar -xvf onnxruntime-linux-loongarch-gpu-1.21.0-{v.r.m}.tgz
cd onnxruntime-linux-loongarch-gpu-1.21.0-{v.r.m}

在 C++ 工程中链接 ORT 库。

假设工程使用 CMake,可直接在 CMakeLists.txt 中添加如下代码进行使用。

find_package(onnxruntime REQUIRED)
target_link_libraries(my_app onnxruntime)

6.2.2. Python 实现伪代码

import onnxruntime as ort

# Load the model and create InferenceSession
model_path = "path/to/your/onnx/model"
session = ort.InferenceSession(model_path)

# Load and preprocess the input image inputTensor
...

# Run inference
outputs = session.run(None, {"input": inputTensor})
print(outputs)

6.2.3. C++ 实现伪代码

#include "onnxruntime_cxx_api.h"

// Load the model and create InferenceSession
Ort::Env env;
std::string model_path = "path/to/your/onnx/model";
Ort::Session session(env, model_path, Ort::SessionOptions{ nullptr });

// Load and preprocess the input image to inputTensor
...

// Run inference
std::vector outputTensors = session.Run(Ort::RunOptions{nullptr},
    inputNames.data(), &inputTensor, inputNames.size(),
    outputNames.data(), outputNames.size());
const float* outputDataPtr = outputTensors[0].GetTensorMutableData();
std::cout << outputDataPtr[0] << std::endl;

6.2.4. 复用编译后模型加速启动

使用 ONNX Runtime 的 LACInfer 执行提供器推理时,ORT 默认在会话初始化阶段对模型执行编译,大型模型会带来明显的启动延迟。可先生成编译模型 .lir 文件,再通过以下两个环境变量让 ORT 直接加载编译好的模型,跳过编译过程,加速启动:

$ export ORT_LACINFER_LOAD_COMPILED_MODEL=1
$ export ORT_LACINFER_LOAD_COMPILE_PATH=/path/to/model.lir

其中:

  • ORT_LACINFER_LOAD_COMPILED_MODEL=1:启用加载编译后模型;
  • ORT_LACINFER_LOAD_COMPILE_PATH:指定编译模型 .lir 文件的路径(由前述 lacinfer 量化/编译流程保存)。

设置后再启动推理进程,ORT 将直接复用该编译后模型,跳过首次编译,显著缩短启动时间:

$ ORT_LACINFER_LOAD_COMPILED_MODEL=1 ORT_LACINFER_LOAD_COMPILE_PATH=/path/to/model.lir python infer.py

6.3. CUDA 程序示例

可以使用如下示例编译 CUDA 的 cu 或 cpp 文件:

$ /opt/lacm/bin/clang++ --target=loongarch64 --cuda-gpu-arch=lg200 -xcuda *.cu/*.cpp
©龙芯开源社区 all right reserved,powered by Gitbook文档更新时间: 2026-09-30 13:16:32

results matching ""

    No results matching ""

    results matching ""

      No results matching ""