Commit 2da5dbc4 by 江名洋

build(docker): 优化 numpy 编译参数以限制 SIMD

1 parent a452c0af
......@@ -3,22 +3,23 @@ FROM python:3.11-slim
# PyPI 镜像加速(清华源)
ENV PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
# 强制禁用 NumPy/OpenBLAS 使用 SSE2 以外的指令(此 CPU 仅有 SSE2)
# 运行时指定 OpenBLAS 使用兼容内核
ENV OPENBLAS_CORETYPE=PRESCOTT
WORKDIR /app
# 安装编译工具链
# 安装编译工具链(numpy 源码编译必需)
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc g++ gfortran libopenblas-dev liblapack-dev \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
# 从源码编译 numpy,禁用 SSE3/SSSE3/SSE4/AVX 等此 CPU 不支持的指令
RUN CFLAGS="-march=x86-64 -mtune=generic -mno-sse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -mno-avx -mno-avx2" \
pip install --no-cache-dir --no-binary=numpy numpy==1.26.4
# 从源码编译 numpy:基线 SSE3(此 CPU 支持),禁止 dispatch 到 SSSE3+
RUN pip install --no-cache-dir --no-binary=numpy numpy==1.26.4 \
-Csetup-args=-Dcpu-baseline=sse3 \
-Csetup-args=-Dcpu-dispatch=none
RUN pip install --no-cache-dir -r requirements.txt
RUN python -c "import numpy; print('numpy version:', numpy.__version__)"
RUN python -c "import numpy; print('numpy:', numpy.__version__)"
COPY . .
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!