Using KML in NumPy
Introduction to NumPy
Numerical Python (NumPy) is a high-performance Python library that supports operations on multidimensional arrays and matrices, and also provides a wide range of mathematical function libraries for array operations. The KML_NUMPY library adapts KML to the C source code of NumPy so that the underlying functions of NumPy can call KML interfaces, thereby further improving performance. Currently, KML_NUMPY adapts to interfaces of basic mathematical operations, FFT, and linear algebra.
Environment Requirements
Currently, KML_NUMPY adapts to NumPy 1.22.4 and 2.0.2, which have different requirements on the build environment.
- The Python version is 3.8 to 3.10 and contains development modules.
If Python is installed and built by yourself, the include directory containing header files such as Python.h usually exists in the Python installation directory. If Python is contained in the system, you can run the yum or apt command to install the Python development package. The installation command is as follows:
yum install python3-devel.aarch64 # Or yum install python3-devel
The python3.x or python3 directory is generated in the /usr/local/include directory, which contains the header files required for developing Python functions. (The example path is /usr/local/include/python3.)
- The GCC version is 8 or later.
- For version 1.22.4, the Cython version must be 0.29.xx; while for version 2.0.2, the Cython version must be 3.0.6 or later, and the meson-python version must be 0.15.0 or later.
- KML has been installed.
Building the KML_NUMPY Library
In the following steps, NumPy 1.22.4 is used.
- Install the open-source NumPy library (v1.22.4).
pip3 install numpy==1.22.4
- Install the Cython library of the 0.29.xx version.
pip3 install cython==0.29.34
- Download kml_adapter and upload it to the build environment (for example, /home).
- Configure environment variables assuming that the HPCKit installation path is /opt/HPCKit.
export KML_PATH=/opt/HPCKit/latest/kml/gcc export PY3_HEADER_PATH=/usr/local/include/python3 export OPT=" -O3 -fopenmp -fopenmp-simd -I numpy/linalg -DHAVE_NEON_NPY -DHAVE_HUAWEI_KML -DNDEBUG -mtune=tsv110 -fno-math-errno -I ${PY3_HEADER_PATH} -I /usr/local/include/ -I ${KML_PATH}/include -L ${KML_PATH}/lib/neon -L ${KML_PATH}/lib/noarch -L ${KML_PATH}/lib/neon/kblas/multi -L ${KML_PATH}/lib/noarch/kvml/single -L ${KML_PATH}/lib/neon/kspblas/single -Wl,-rpath=${KML_PATH}/lib/neon -Wl,-rpath=${KML_PATH}/lib/noarch -Wl,-rpath=${KML_PATH}/lib/neon/kblas/multi -Wl,-rpath=${KML_PATH}/lib/noarch/kvml/single -Wl,-rpath=${KML_PATH}/lib/neon/kspblas/single -lkblas -lkvml -lkm -lkspblas -lklapack -lknpy -lkfft -lkfftf -lkm_l9 -lm -lksvml -lgfortran" - Perform compilation.
cd /home/kml_adapter/numpy_adapter NPY_BLAS_ORDER= NPY_LAPACK_ORDER= python3 setup.py build -j16
- Check whether the compilation is successful.
If the compilation is successful, the following directories are generated in numpy_adapter/build/ based on your environment:
lib.linux-aarch64-3.x src.linux-aarch64-3.x temp.linux-aarch64-3.x
In the following steps, NumPy 2.0.2 is used.
- Download the NumPy 2.0.2 source code.
- Download the subprogram.
1git submodule update --init --recursive
- Run the following command in the root directory.
1sed -i "s|\$PREFIX|$(pwd)|g" pyproject.toml
- Add the following environment variable and point it to the path where pcfiles is located.
1export PKG_CONFIG_PATH=$PWD/pcfiles
- Perform the compilation.
1python -m build
Enabling KML in NumPy
NumPy 1.22.4:
Configure environment variables to ensure that KML_NUMPY is preferentially called. (Assume that kml_adapter/numpy_adapter/build/lib.linux-aarch64-3.10 is generated.)
export PYTHONPATH=/home/kml_adapter/numpy_adapter/build/lib.linux-aarch64-3.10:$PYTHONPATH
NumPy 2.0.2:
If the preceding steps are successful, a .whl file is generated in the dist directory, for example, numpy-2.0.2-cp39-cp39-linux_aarch64.whl.
pip install numpy-2.0.2-cp39-cp39-linux_aarch64.whl