• Bug#1105821: onnxruntime: FTBFS: Cherry-pick upstream patch to fix erro

    From zhangdandan@21:1/5 to All on Thu May 15 15:10:01 2025
    This is a multi-part message in MIME format.
    Source: onnxruntime
    Version: 1.21.0+dfsg-1
    Severity: normal
    Tags: FTBFS patch
    User: debian-loongarch@lists.debian.org
    Usertags: loong64

    Dear maintainers,

    Compiling the onnxruntime failed for loong64 in the Debian Package Auto-Building environment.
    The error log is as follows,
    ```
    /<<PKGBUILDDIR>>/onnxruntime/core/mlas/lib/quantize.cpp:1707:88: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
     1707 |     const __m128 MinimumValueVector = MlasReinterpretAsFloat32x4(__lsx_vreplgr2vr_w( *((uint32_t*)&min_f)));
    | ~^~~~~~~~~~~~~~~~~~ /<<PKGBUILDDIR>>/onnxruntime/core/mlas/lib/quantize.cpp:1708:88: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
     1708 |     const __m128 MaximumValueVector = MlasReinterpretAsFloat32x4(__lsx_vreplgr2vr_w( *((uint32_t*)&max_f)));
    | ~^~~~~~~~~~~~~~~~~~
    ```
    The full build log can be found at https://buildd.debian.org/status/fetch.php?pkg=onnxruntime&arch=loong64&ver=1.21.0%2Bdfsg-1&stamp=1742453939&raw=0.

    We need to cherry-pick upstream patch to fix error caused by "-Werror=strict-aliasing", details can be found at https://github.com/microsoft/onnxruntime/pull/24578.
    Due to upstream release version is v1.22 which does not include this patch. Please consider the patch I attached.

    Based on the attached patch, onnxruntime (1.21.0+dfsg-1+loong64) was
    built successfully on locally.
    ```
       dh_builddeb -O--buildsystem=cmake\+ninja -O--sourcedirectory=cmake -O--builddirectory=.
    dpkg-deb: building package 'libonnxruntime1.21-dbgsym' in '../libonnxruntime1.21-dbgsym_1.21.0+dfsg-1+loong64_loong64.deb'.
    dpkg-deb: building package 'libonnxruntime1.21' in '../libonnxruntime1.21_1.21.0+dfsg-1+loong64_loong64.deb'.
    dpkg-deb: building package 'libonnxruntime-dev' in '../libonnxruntime-dev_1.21.0+dfsg-1+loong64_loong64.deb'.
    dpkg-deb: building package 'onnxruntime-tools' in '../onnxruntime-tools_1.21.0+dfsg-1+loong64_all.deb'.
    dpkg-deb: building package 'python3-onnxruntime' in '../python3-onnxruntime_1.21.0+dfsg-1+loong64_loong64.deb'.
    dpkg-deb: building package 'python3-onnxruntime-dbgsym' in '../python3-onnxruntime-dbgsym_1.21.0+dfsg-1+loong64_loong64.deb'.
     dpkg-genbuildinfo -O../onnxruntime_1.21.0+dfsg-1+loong64_loong64.buildinfo
     dpkg-genchanges -O../onnxruntime_1.21.0+dfsg-1+loong64_loong64.changes
    ```

    Best Regards,
    Dandan Zhang


    Description: Fix error caused by "-Werror=strict-aliasing".
    .
    onnxruntime (1.21.0+dfsg-1+loong64) unstable; urgency=medium
    .
    * Cherry-pick upstream patch.
    - Fix warning and fix transpose store op for LoongArch.
    Author: Dandan Zhang <zhangdandan@loongson.cn>

    ---
    Applied-Upstream: master, https://github.com/microsoft/onnxruntime/pull/24578. Last-Update: 2025-05-15

    --- onnxruntime-1.21.0+dfsg.orig/onnxruntime/core/mlas/lib/quantize.cpp
    +++ onnxruntime-1.21.0+dfsg/onnxruntime/core/mlas/lib/quantize.cpp
    @@ -1704,8 +1704,8 @@ MlasRequantizeOutput(
    float min_f = float(std::numeric_limits<OutputType>::lowest() - ZeroPoint);
    float max_f = float(std::numeric_limits<OutputType>::max() - ZeroPoint);
    const __m128 PerMatrixScaleVector = PerColumnScale ? MlasReinterpretAsFloat32x4(__lsx_vldi(0)) : MlasReinterpretAsFloat32x4(__lsx_vldrepl_w(Scale, 0));
    - const __m128 MinimumValueVector = MlasReinterpretAsFloat32x4(__lsx_vreplgr2vr_w( *((uint32_t*)&min_f)));
    - const __m128 MaximumValueVector = MlasReinterpretAsFloat32x4(__lsx_vreplgr2vr_w( *((uint32_t*)&max_f)));
    + const __m128 MinimumValueVector = MlasReinterpretAsFloat32x4((__m128i)(v4f32){min_f,min_f,min_f,min_f});
    + const __m128 MaximumValueVector = MlasReinterpretAsFloat32x4((__m128i