chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:40:42 +08:00
commit e25996e7db
15472 changed files with 3536181 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
configure_file(submit_local.sh.in paddle @ONLY)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/paddle
DESTINATION bin
PERMISSIONS
OWNER_EXECUTE
OWNER_WRITE
OWNER_READ
GROUP_EXECUTE
GROUP_READ
WORLD_EXECUTE
WORLD_READ)
+175
View File
@@ -0,0 +1,175 @@
# Building PaddlePaddle
## Goals
We want to make the building procedures:
1. Static, can reproduce easily.
1. Generate python `whl` packages that can be widely use cross many distributions.
1. Build different binaries per release to satisfy different environments:
- Binaries for different CUDA and CUDNN versions, like CUDA 7.5, 8.0, 9.0
- Binaries containing only capi
- Binaries for python with wide unicode support or not.
1. Build docker images with PaddlePaddle pre-installed, so that we can run
PaddlePaddle applications directly in docker or on Kubernetes clusters.
To achieve this, we maintain a dockerhub repo:https://hub.docker.com/r/paddlepaddle/paddle
which provides pre-built environment images to build PaddlePaddle and generate corresponding `whl`
binaries.(**We strongly recommend building paddlepaddle in our pre-specified Docker environment.**)
## Development Workflow
Here we describe how the workflow goes on. We start from considering our daily development environment.
Developers work on a computer, which is usually a laptop or desktop:
<img src="doc/paddle-development-environment.png" width=500 />
or, they might rely on a more sophisticated box (like with GPUs):
<img src="doc/paddle-development-environment-gpu.png" width=500 />
A principle here is that source code lies on the development computer (host) so that editors like Eclipse can parse the source code to support auto-completion.
## Build With Docker
### Build Environments
The latest pre-built build environment images are:
| Image | Tag |
| ----- | --- |
| paddlepaddle/paddle | latest-dev |
### Start Build
```bash
git clone https://github.com/PaddlePaddle/Paddle.git
cd Paddle
./paddle/scripts/paddle_docker_build.sh build
```
After the build finishes, you can get output `whl` package under
`build/python/dist`.
This command will download the most recent dev image from docker hub, start a container in the backend and then run the build script `/paddle/paddle/scripts/paddle_build.sh build` in the container.
The container mounts the source directory on the host into `/paddle`.
When it writes to `/paddle/build` in the container, it writes to `$PWD/build` on the host indeed.
### Build Options
Users can specify the following Docker build arguments with either "ON" or "OFF" value:
| Option | Default | Description |
| ------ | -------- | ----------- |
| `WITH_GPU` | OFF | Generates NVIDIA CUDA GPU code and relies on CUDA libraries. |
| `WITH_AVX` | OFF | Set to "ON" to enable AVX support. |
| `WITH_TESTING` | OFF | Build unit tests binaries. |
| `WITH_MKL` | ON | Build with [Intel® oneMKL](https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html) and [Intel® oneDNN](https://github.com/uxlfoundation/oneDNN) support. |
| `WITH_PYTHON` | ON | Build with python support. Turn this off if build is only for capi. |
| `WITH_STYLE_CHECK` | ON | Check the code style when building. |
| `PYTHON_ABI` | "" | Build for different python ABI support, can be cp27-cp27m or cp27-cp27mu |
| `RUN_TEST` | OFF | Run unit test immediately after the build. |
## Docker Images
You can get the latest PaddlePaddle docker images by
`docker pull paddlepaddle/paddle:<version>` or build one by yourself.
### Official Docker Releases
Official docker images at
[here](https://hub.docker.com/r/paddlepaddle/paddle/tags/),
you can choose either latest or images with a release tag like `0.10.0`,
Currently available tags are:
| Tag | Description |
| ------ | --------------------- |
| latest | latest CPU only image |
| latest-gpu | latest binary with GPU support |
| 0.10.0 | release 0.10.0 CPU only binary image |
| 0.10.0-gpu | release 0.10.0 with GPU support |
### Build Your Own Image
Build PaddlePaddle docker images are quite simple since PaddlePaddle can
be installed by just running `pip install`. A sample `Dockerfile` is:
```dockerfile
FROM nvidia/cuda:7.5-cudnn5-runtime-centos6
RUN yum install -y centos-release-SCL
RUN yum install -y python27
# This whl package is generated by previous build steps.
ADD python/dist/paddlepaddle-0.10.0-cp27-cp27mu-linux_x86_64.whl /
RUN pip install /paddlepaddle-0.10.0-cp27-cp27mu-linux_x86_64.whl && rm -f /*.whl
```
Then build the image by running `docker build -t [REPO]/paddle:[TAG] .` under
the directory containing your own `Dockerfile`.
We also release a script and Dockerfile for building PaddlePaddle docker images
across different cuda versions. To build these docker images, run:
```bash
bash ./build_docker_images.sh
docker build -t [REPO]/paddle:tag -f [generated_docker_file] .
```
- NOTE: note that you can choose different base images for your environment, you can find all the versions [here](https://hub.docker.com/r/nvidia/cuda/).
### Use Docker Images
Suppose that you have written an application program `train.py` using
PaddlePaddle, we can test and run it using docker:
```bash
docker run --rm -it -v $PWD:/work paddlepaddle/paddle /work/a.py
```
But this works only if all dependencies of `train.py` are in the production image. If this is not the case, we need to build a new Docker image from the production image and with more dependencies installs.
### Run PaddlePaddle Book In Docker
Our [book repo](https://github.com/paddlepaddle/book) also provide a docker
image to start a jupiter notebook inside docker so that you can run this book
using docker:
```bash
docker run -d -p 8888:8888 paddlepaddle/book
```
Please refer to https://github.com/paddlepaddle/book if you want to build this
docker image by your self.
### Run Distributed Applications
In our [API design doc](https://github.com/PaddlePaddle/Paddle/blob/develop/doc/design/api.md#distributed-training), we proposed an API that starts a distributed training job on a cluster. This API need to build a PaddlePaddle application into a Docker image as above and calls kubectl to run it on the cluster. This API might need to generate a Dockerfile look like above and call `docker build`.
Of course, we can manually build an application image and launch the job using the kubectl tool:
```bash
docker build -f some/Dockerfile -t myapp .
docker tag myapp me/myapp
docker push
kubectl ...
```
## More Options
### Build Without Docker
Follow the *Dockerfile* in the paddlepaddle repo to set up your local dev environment and run:
```bash
./paddle/scripts/paddle_build.sh build
```
### Additional Tasks
You can get the help menu for the build scripts by running with no options:
```bash
./paddle/scripts/paddle_build.sh
or ./paddle/scripts/paddle_docker_build.sh
```
+7
View File
@@ -0,0 +1,7 @@
setuptools==57.4.0 ; python_version <= '3.11' and sys_platform == 'win32'
setuptools==69.0.2 ; python_version > '3.11' and sys_platform == 'win32'
wheel==0.45.1 ; sys_platform == 'win32'
pyyaml ; sys_platform == 'win32'
wget ; sys_platform == 'win32'
jinja2 ; sys_platform == 'linux'
pybind11_stubgen ; sys_platform == 'linux'
Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

+40
View File
@@ -0,0 +1,40 @@
# Locales
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
# Aliases
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias ls='ls -hFG'
alias l='ls -lF'
alias ll='ls -alF'
alias lt='ls -ltrF'
alias ll='ls -alF'
alias lls='ls -alSrF'
alias llt='ls -altrF'
# Colorize directory listing
alias ls="ls -ph --color=auto"
# Colorize grep
if echo hello|grep --color=auto l >/dev/null 2>&1; then
export GREP_OPTIONS="--color=auto" GREP_COLOR="1;31"
fi
# Shell
export CLICOLOR="1"
YELLOW="\[\033[1;33m\]"
NO_COLOUR="\[\033[0m\]"
GREEN="\[\033[1;32m\]"
WHITE="\[\033[1;37m\]"
export PS1="\[\033[1;33m\]λ $WHITE\h $GREEN\w $NO_COLOUR"
+43
View File
@@ -0,0 +1,43 @@
[user]
name =
email =
[alias]
st = status --branch --short
ci = commit
br = branch
co = checkout
df = diff
l = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
ll = log --stat
[merge]
tool = vimdiff
[core]
excludesfile = ~/.gitignore
editor = vim
[color]
branch = auto
diff = auto
status = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = yellow
changed = green
untracked = cyan
[push]
default = matching
File diff suppressed because it is too large Load Diff
+51
View File
@@ -0,0 +1,51 @@
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import subprocess
import sys
class HandleTarget:
def __init__(self) -> None:
argv = sys.argv
len_ = len(argv)
fromPath = './' if len_ <= 1 else argv[1]
cmd = f"find {fromPath} -name '*.o' -not -path './third_party/*' | xargs du -sch > log"
subprocess.run(cmd, shell=True)
def calcuSize(self, item):
size = float(item[:-1])
res = size * 1024 if item.find('G') >= 0 else size
return size / 1024 if item.find('K') >= 0 else res
def getSize(self):
ctx = self.getDatas()
sum = 0
for item in ctx:
if item.find('total') >= 0:
item = item.split('\t')[0]
sum += self.calcuSize(item)
print(f"Total size is {sum} M (without third_party)")
def getDatas(self):
with open('log', 'r') as file:
ctx = file.read()
ctx = ctx.split('\n')
return ctx
if __name__ == '__main__':
handler = HandleTarget()
handler.getSize()
+18
View File
@@ -0,0 +1,18 @@
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import paddle as pd
pd.utils.run_check()
print(pd.__version__)
+71
View File
@@ -0,0 +1,71 @@
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
ARG PYTHON_VERSION=3.7
FROM python:${PYTHON_VERSION}-alpine3.11
USER root
WORKDIR /root
VOLUME /root/.ccache
VOLUME /root/.cache
RUN apk update
RUN apk add --no-cache \
g++ gfortran make cmake patchelf git ccache
ARG package
RUN if [ "$package" ]; then \
set -e; \
pkgs=$(echo "$package" | base64 -d -); \
echo ">>> decode package:"; \
echo "$pkgs"; \
for nm in $pkgs; do \
echo ">>> install package: $nm"; \
apk add --no-cache --force-overwrite "$nm"; \
done; \
fi
ARG requirement
ARG requirement_ut
ARG pip_index
RUN if [ "$requirement" ]; then \
set -e; \
echo "$requirement" | base64 -d - > "requirement.txt"; \
echo ">>> decode requirement:"; \
cat "requirement.txt"; \
echo ">>> install python requirement:"; \
PIP_ARGS="--timeout 300"; \
if [ "$pip_index" ]; then \
PIP_DOMAIN=$(echo "$pip_index" | awk -F/ '{print $3}'); \
PIP_ARGS="$PIP_ARGS -i $pip_index --trusted-host $PIP_DOMAIN"; \
echo ">>> pip index: $pip_index"; \
fi; \
pip3 install $PIP_ARGS -r "requirement.txt"; \
rm -f "requirement.txt"; \
if [ "$requirement_ut" ]; then \
echo "$requirement_ut" | base64 -d - > "requirement_ut.txt"; \
cat "requirement_ut.txt"; \
pip3 install $PIP_ARGS -r "requirement_ut.txt"; \
rm -f "requirement_ut.txt"; \
fi; \
fi
ENTRYPOINT [ "/bin/sh" ]
+121
View File
@@ -0,0 +1,121 @@
Paddle for Linux-musl Usage Guide
===========================================
# Introduction
Paddle can be built for linux-musl such as alpine, and be used in libos-liked SGX TEE environment. Currently supported commercial product TEE Scone, and community maintanced TEE Occlum. We also working on to support open source TEE Graphene.
# Build Automatically
1. clone paddle source from github
```bash
git clone https://github.com/PaddlePaddle/Paddle.git
```
2. setup build directory
```bash
# enter paddle directory
cd ./Paddle
# create and enter building directory
mkdir -p build && cd build
```
3. build docker for compiling. use environment HTTP_PROXY/HTTPS_PROXY for proxy setup.
```bash
# setup proxy address, when the speed of internet is not good.
# export HTTP_PROXY='http://127.0.0.1:8080'
# export HTTPS_PROXY='https://127.0.0.1:8080'
# invoke build script
../paddle/scripts/musl_build/build_docker.sh
```
4. compile paddle in previous built docker. proxy setup method is same as previous step.
```bash
# setup proxy address, when the speed of internet is not good.
# export HTTP_PROXY='http://127.0.0.1:8080'
# export HTTPS_PROXY='https://127.0.0.1:8080'
# invoke build paddle script
# all arguments, such as -j8 optional, is past to make procedure.
../paddle/scripts/musl_build/build_paddle.sh -j8
# find output wheel package
# output wheel packages will save to "./output" directory.
ls ./output/*.whl
```
# Build Manually
1. start up the building docker, and enter the shell in the container
```bash
# checkout paddle source code
git clone https://github.com/PaddlePaddle/Paddle.git
# enter paddle directory
cd ./Paddle
# build docker image
../paddle/scripts/musl_build/build_docker.sh
# enter the container interactive shell
BUILD_MAN=1 ../paddle/scripts/musl_build/build_paddle.sh
```
2. type commands and compile source manually
```sh
# compile paddle by commands
# paddle is mount to /paddle directory
# working directory is /root
mkdir build && cd build
# install python requirement
pip install -r /paddle/python/requirements.txt
# configure project with cmake
cmake -DWITH_MUSL=ON -DWITH_CRYPTO=OFF -DWITH_MKL=OFF -DWITH_GPU=OFF /paddle
# run the make to build project.
# the argument -j8 is optional to accelerate compiling.
make -j8
```
# Scripts
1. **build_docker.sh**
compiling docker building script. it use alpine linux 3.10 as musl linux build environment. it will try to install all the compiling tools, development packages, and python requirements for paddle musl compiling.
environment variables:
- PYTHON_VERSION: the version of python used for image building, default=3.8.
- WITH_PRUNE_DAYS: prune old docker images, with days limitation.
- WITH_REBUILD: force to rebuild the image, default=0.
- WITH_REQUIREMENT: build with the python requirements, default=1.
- WITH_UT_REQUIREMENT: build with the unit test requirements, default=0.
- WITH_PIP_INDEX: use custom pip index when pip install packages.
- ONLY_NAME: only print the docker name, and exit.
- HTTP_PROXY: use http proxy.
- HTTPS_PROXY: use https proxy.
2. **build_paddle.sh** automatically or manually paddle building script. it will mount the root directory of paddle source to /paddle, and run compile procedure in /root/build directory. the output wheel package will save to the ./output directory relative to working directory.
environment variables:
- BUILD_MAN: build the paddle manually, default=0.
- WITH_TEST: build with unittest, and run unittest check, default=0.
- WITH_PRUNE_CONTAINER: remove the container after building, default=1.
- CTEST_*: CTEST flags used for unit test.
- FLAGS_*: build flags used for paddle building.
- HTTP_PROXY: use http proxy.
- HTTPS_PROXY: use https proxy.
# Files
- **build_docker.sh**: docker building script
- **build_paddle.sh**: paddle building script
- **build_inside.sh**: build_paddle.sh will invoke this script inside the docker for compiling.
- **config.sh**: build config script for configure compiling option setting.
- **Dockerfile**: build docker definition file.
- **package.txt**: build required develop packages for alpine linux.
- **README.md**: this file.
+41
View File
@@ -0,0 +1,41 @@
#!/bin/bash
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
CUR_DIR=$(dirname "${BASH_SOURCE[0]}")
CUR_DIR=$(realpath "$CUR_DIR")
# shellcheck disable=2034
PADDLE_DIR=$(realpath "$CUR_DIR/../../../")
MOUNT_DIR="/paddle"
BUILD_DOCKERFILE="$CUR_DIR/Dockerfile"
PACKAGE_REQ="$CUR_DIR/package.txt"
PYTHON_REQ="python/requirements.txt"
UNITTEST_REQ="python/unittest_py/requirements.txt"
function chksum(){
cat $* | md5sum - | cut -b-8
}
# shellcheck disable=2034
BUILD_NAME="paddle-musl-build"
BUILD_TAG=$(chksum "$BUILD_DOCKERFILE" "$PACKAGE_REQ")
BUILD_IMAGE="$BUILD_NAME:$BUILD_TAG"
BUILD_CONTAINER="$BUILD_NAME-$(date +%Y%m%d-%H%M%S)"
CCACHE_DIR="${CCACHE_DIR-${HOME}/.paddle-musl/ccache}"
CACHE_DIR="${CACHE_DIR-${HOME}/.paddle-musl/cache}"
+9
View File
@@ -0,0 +1,9 @@
linux-headers
freetype-dev
libjpeg-turbo-dev
zlib-dev
lapack-dev
openblas-dev
openssl-dev
libuv-dev
graphviz
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+71
View File
@@ -0,0 +1,71 @@
#!/usr/bin/env bash
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
function start_build_docker() {
docker pull $IMG
apt_mirror='s#http://archive.ubuntu.com/ubuntu#mirror://mirrors.ubuntu.com/mirrors.txt#g'
DOCKER_ENV=$(cat <<EOL
-e FLAGS_fraction_of_gpu_memory_to_use=0.15 \
-e CTEST_OUTPUT_ON_FAILURE=1 \
-e CTEST_PARALLEL_LEVEL=1 \
-e APT_MIRROR=${apt_mirror} \
-e WITH_GPU=ON \
-e CUDA_ARCH_NAME=Auto \
-e WITH_AVX=ON \
-e WITH_TESTING=ON \
-e WITH_COVERAGE=ON \
-e COVERALLS_UPLOAD=ON \
-e WITH_DEB=OFF \
-e CMAKE_BUILD_TYPE=RelWithDebInfo \
-e PADDLE_FRACTION_GPU_MEMORY_TO_USE=0.15 \
-e CUDA_VISIBLE_DEVICES=0,1 \
-e WITH_DISTRIBUTE=ON \
-e RUN_TEST=ON
EOL
)
DOCKER_CMD="nvidia-docker"
if ! [ -x "$(command -v ${DOCKER_CMD})" ]; then
DOCKER_CMD="docker"
fi
if [ ! -d "${HOME}/.ccache" ]; then
mkdir ${HOME}/.ccache
fi
set -ex
${DOCKER_CMD} run -it \
${DOCKER_ENV} \
-e SCRIPT_NAME=$0 \
-e CONTENT_DEC_PASSWD=$CONTENT_DEC_PASSWD \
-e TRAVIS_BRANCH=$TRAVIS_BRANCH \
-e TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST \
-v $PADDLE_ROOT:/paddle \
-v ${HOME}/.ccache:/root/.ccache \
-w /paddle \
$IMG \
paddle/scripts/paddle_build.sh $@
set +x
}
function main() {
DOCKER_REPO="paddlepaddle/paddle"
VERSION="latest-dev"
PADDLE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/../../" && pwd )"
IMG=${DOCKER_REPO}:${VERSION}
start_build_docker $@
}
main $@
+169
View File
@@ -0,0 +1,169 @@
#!/bin/bash
function version(){
echo "PaddlePaddle @PADDLE_VERSION@, compiled with"
echo " with_avx: @WITH_AVX@"
echo " with_gpu: @WITH_GPU@"
echo " with_mkl: @WITH_MKL@"
echo " with_mkldnn: @WITH_ONEDNN@"
echo " with_python: @WITH_PYTHON@"
}
function ver2num() {
set -e
# convert version to number.
if [ -z "$1" ]; then # empty argument
printf "%03d%03d%03d%03d%03d" 0
else
local VERN=$(echo $1 | sed 's#v##g' | sed 's#\.# #g' \
| sed 's#a# 0 #g' | sed 's#b# 1 #g' | sed 's#rc# 2 #g')
if [ `echo $VERN | wc -w` -eq 3 ] ; then
printf "%03d%03d%03d%03d%03d" $VERN 999 999
else
printf "%03d%03d%03d%03d%03d" $VERN
fi
fi
set +e
}
function cpu_config() {
# auto set KMP_AFFINITY and OMP_DYNAMIC from Hyper Threading Status
# only when MKL enabled
if [ "@WITH_MKL@" == "OFF" ]; then
return 0
fi
platform="`uname -s`"
ht=0
if [ $platform == "Linux" ]; then
ht=`lscpu |grep "per core"|awk -F':' '{print $2}'|xargs`
elif [ $platform == "Darwin" ]; then
if [ `sysctl -n hw.physicalcpu` -eq `sysctl -n hw.logicalcpu` ]; then
# HT is OFF
ht=1
fi
else
return 0
fi
if [ $ht -eq 1 ]; then # HT is OFF
if [ -z "$KMP_AFFINITY" ]; then
export KMP_AFFINITY="granularity=fine,compact,0,0"
fi
if [ -z "$OMP_DYNAMIC" ]; then
export OMP_DYNAMIC="FALSE"
fi
else # HT is ON
if [ -z "$KMP_AFFINITY" ]; then
export KMP_AFFINITY="granularity=fine,compact,1,0"
fi
if [ -z "$OMP_DYNAMIC" ]; then
export OMP_DYNAMIC="True"
fi
fi
}
function threads_config() {
# auto set OMP_NUM_THREADS and MKL_NUM_THREADS
# according to trainer_count and total processors
# only when MKL enabled
# auto set OPENBLAS_NUM_THREADS when do not use MKL
platform="`uname -s`"
processors=0
if [ $platform == "Linux" ]; then
processors=`grep "processor" /proc/cpuinfo|sort -u|wc -l`
elif [ $platform == "Darwin" ]; then
processors=`sysctl -n hw.logicalcpu`
else
return 0
fi
trainers=`grep -Eo 'trainer_count.[0-9]+' <<< "$@" |grep -Eo '[0-9]+'|xargs`
if [ -z $trainers ]; then
trainers=1
fi
threads=$((processors / trainers))
if [ $threads -eq 0 ]; then
threads=1
fi
if [ "@WITH_MKL@" == "ON" ]; then
if [ -z "$OMP_NUM_THREADS" ]; then
export OMP_NUM_THREADS=$threads
fi
if [ -z "$MKL_NUM_THREADS" ]; then
export MKL_NUM_THREADS=$threads
fi
else
if [ -z "$OPENBLAS_NUM_THREADS" ]; then
export OPENBLAS_NUM_THREADS=$threads
fi
if [ $threads -gt 1 ] && [ -z "$OPENBLAS_MAIN_FREE" ]; then
export OPENBLAS_MAIN_FREE=1
fi
fi
}
PADDLE_CONF_HOME="$HOME/.config/paddle"
mkdir -p ${PADDLE_CONF_HOME}
if [ -z "${PADDLE_NO_STAT+x}" ]; then
SERVER_VER=`curl -m 5 -X POST --data content="{ \"version\": \"@PADDLE_VERSION@\" }"\
-b ${PADDLE_CONF_HOME}/paddle.cookie \
-c ${PADDLE_CONF_HOME}/paddle.cookie \
http://api.paddlepaddle.org/version 2>/dev/null`
if [ $? -eq 0 ] && [ "$(ver2num @PADDLE_VERSION@)" -lt $(ver2num $SERVER_VER) ]; then
echo "Paddle release a new version ${SERVER_VER}, you can get the install package in http://www.paddlepaddle.org"
fi
fi
PADDLE_BIN_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ ! -z "${DEBUGGER}" ]; then
echo "Using debug command ${DEBUGGER}"
fi
CUDNN_LIB_PATH="@CUDNN_LIB_PATH@"
if [ ! -z "${CUDNN_LIB_PATH}" ]; then
export LD_LIBRARY_PATH=${CUDNN_LIB_PATH}:${LD_LIBRARY_PATH}
fi
export PYTHONPATH=${PWD}:${PYTHONPATH}
# Check python lib installed or not.
pip --help > /dev/null
if [ $? -ne 0 ]; then
echo "pip should be installed to run paddle."
exit 1
fi
if [ "@WITH_GPU@" == "ON" ]; then
PADDLE_NAME="paddlepaddle-gpu"
else
PADDLE_NAME="paddlepaddle"
fi
INSTALLED_VERSION=`pip freeze 2>/dev/null | grep "^${PADDLE_NAME}==" | sed 's/.*==//g'`
if [ -z "${INSTALLED_VERSION}" ]; then
INSTALLED_VERSION="0.0.0" # not installed
fi
cat <<EOF | python -
from distutils.version import LooseVersion
import sys
if LooseVersion("${INSTALLED_VERSION}") < LooseVersion("@PADDLE_VERSION@"):
sys.exit(1)
else:
sys.exit(0)
EOF
cpu_config
# echo $KMP_AFFINITY $OMP_DYNAMIC
case "$1" in
"version")
version
;;
*)
version
;;
esac
+187
View File
@@ -0,0 +1,187 @@
@ECHO OFF
SETLOCAL
set source_path=%1
set PYTHON_DIR=%2
set WITH_GPU=%3
set WITH_MKL=%4
set ON_INFER=%5
set PADDLE_VERSION=%6
set BATDIR=%7
set CUDA_DIR=%8
set RETRY_TIMES=3
set CUDA_DIR_WIN=%CUDA_DIR:/=\%
set PATH=%CUDA_DIR_WIN%\nvvm\bin\;%CUDA_DIR_WIN%\bin;%PATH%
for /f "tokens=1,2,* delims=\\" %%a in ("%PYTHON_DIR%") do (
set c1=%%a
set c2=%%b
)
set PYTHONV=%c2%
echo %CUDA_DIR% | findstr 10.0 > NULL
if %errorlevel% == 0 (set PADDLE_VERSION=%PADDLE_VERSION%
set CUDAV=v10.0)
echo %CUDA_DIR% | findstr 9.2 > NULL
if %errorlevel% == 0 (set PADDLE_VERSION=%PADDLE_VERSION%.post97
set CUDAV=v9.2)
echo %CUDA_DIR% | findstr 9.0 > NULL
if %errorlevel% == 0 (set PADDLE_VERSION=%PADDLE_VERSION%.post97
set CUDAV=v9.0)
echo %CUDA_DIR% | findstr 8.0 > NULL
if %errorlevel% == 0 (set PADDLE_VERSION=%PADDLE_VERSION%.post87
set CUDAV=v8.0)
set PLAT=GPU
if "%WITH_GPU%"=="OFF" (
set PLAT=CPU
set CUDAV=CPU
)
if "%WITH_MKL%"=="ON" (
set BLAS=MKL
) else (
set BLAS=OPEN
)
if "%ON_INFER%"=="ON" (
goto :INFERENCE_LIBRARY
)
echo "begin to do build noavx ..."
set "dst_path=%source_path%\build_%PYTHONV%_%PLAT%_%BLAS%_%CUDAV%_noavx"
if exist %dst_path% rmdir /q /s %dst_path%
mkdir %dst_path%
cd /d %dst_path%
echo Current directory : %cd%
call:rest_env
echo cmake %dst_path%\..\Paddle -G "Visual Studio 15 2017 Win64" -T host=x64 -DWITH_GPU=%WITH_GPU% -DWITH_MKL=%WITH_MKL% -DWITH_AVX=OFF -DPYTHON_INCLUDE_DIR=%PYTHON_DIR%\include\ -DPYTHON_LIBRARY=%PYTHON_DIR%\libs\ -DPYTHON_EXECUTABLE=%PYTHON_DIR%\python.exe -DCMAKE_BUILD_TYPE=Release -DWITH_TESTING=OFF -DWITH_PYTHON=ON -DCUDA_TOOLKIT_ROOT_DIR=%CUDA_DIR% -DCUDA_ARCH_NAME=All
cmake %dst_path%\..\Paddle -G "Visual Studio 15 2017 Win64" -T host=x64 -DWITH_GPU=%WITH_GPU% -DWITH_MKL=%WITH_MKL% -DWITH_AVX=OFF -DPYTHON_INCLUDE_DIR=%PYTHON_DIR%\include\ -DPYTHON_LIBRARY=%PYTHON_DIR%\libs\ -DPYTHON_EXECUTABLE=%PYTHON_DIR%\python.exe -DCMAKE_BUILD_TYPE=Release -DWITH_TESTING=OFF -DWITH_PYTHON=ON -DCUDA_TOOLKIT_ROOT_DIR=%CUDA_DIR% -DCUDA_ARCH_NAME=All
set MSBUILDDISABLENODEREUSE=1
set BUILD_TYPE=NO_AVX
call:Build
REM -------------------------------------------------------------------------
echo "begin to do build avx ..."
set "dst_path=%source_path%\build_%PYTHONV%_%PLAT%_%BLAS%_%CUDAV%"
if exist %dst_path% rmdir /q /s %dst_path%
mkdir %dst_path%
cd /d %dst_path%
echo Current directory : %cd%
call:rest_env
echo cmake %dst_path%\..\Paddle -G "Visual Studio 15 2017 Win64" -T host=x64 -DWITH_GPU=%WITH_GPU% -DWITH_MKL=%WITH_MKL% -DWITH_AVX=ON -DPYTHON_INCLUDE_DIR=%PYTHON_DIR%\include\ -DPYTHON_LIBRARY=%PYTHON_DIR%\libs\ -DPYTHON_EXECUTABLE=%PYTHON_DIR%\python.exe -DCMAKE_BUILD_TYPE=Release -DWITH_TESTING=OFF -DWITH_PYTHON=ON -DCUDA_TOOLKIT_ROOT_DIR=%CUDA_DIR% -DCUDA_ARCH_NAME=All
cmake %dst_path%\..\Paddle -G "Visual Studio 15 2017 Win64" -T host=x64 -DWITH_GPU=%WITH_GPU% -DWITH_MKL=%WITH_MKL% -DWITH_AVX=ON -DPYTHON_INCLUDE_DIR=%PYTHON_DIR%\include\ -DPYTHON_LIBRARY=%PYTHON_DIR%\libs\ -DPYTHON_EXECUTABLE=%PYTHON_DIR%\python.exe -DCMAKE_BUILD_TYPE=Release -DWITH_TESTING=OFF -DWITH_PYTHON=ON -DCUDA_TOOLKIT_ROOT_DIR=%CUDA_DIR% -DCUDA_ARCH_NAME=All
set MSBUILDDISABLENODEREUSE=1
set BUILD_TYPE=AVX
call:Build
echo BUILD WHL PACKAGE COMPLETE
goto :END
REM -------------------------------------------------------------------------
:INFERENCE_LIBRARY
echo "begin to do build inference library ..."
set "dst_path=%source_path%\build_INFERENCE_LIBRARY_%PLAT%_%BLAS%_%CUDAV%"
if exist %dst_path% rmdir /q /s %dst_path%
mkdir %dst_path%
cd /d %dst_path%
echo Current directory : %cd%
call:rest_env
echo cmake %dst_path%\..\Paddle -G "Visual Studio 15 2017 Win64" -T host=x64 -DWITH_GPU=%WITH_GPU% -DWITH_MKL=%WITH_MKL% -DCMAKE_BUILD_TYPE=Release -DWITH_PYTHON=OFF -DON_INFER=ON -DCUDA_TOOLKIT_ROOT_DIR=%CUDA_DIR% -DCUDA_ARCH_NAME=All
cmake %dst_path%\..\Paddle -G "Visual Studio 15 2017 Win64" -T host=x64 -DWITH_GPU=%WITH_GPU% -DWITH_MKL=%WITH_MKL% -DCMAKE_BUILD_TYPE=Release -DWITH_PYTHON=OFF -DON_INFER=ON -DCUDA_TOOLKIT_ROOT_DIR=%CUDA_DIR% -DCUDA_ARCH_NAME=All
set MSBUILDDISABLENODEREUSE=1
set BUILD_TYPE=INFERENCE LIBRARY
call:Build
echo PACKAGE INFERENCE LIBRARY
mkdir inference_dist
%PYTHON_DIR%\python.exe -c "import shutil;shutil.make_archive('inference_dist/paddle_inference_install_dir', 'zip', root_dir='paddle_inference_install_dir')"
%PYTHON_DIR%\python.exe -c "import shutil;shutil.make_archive('inference_dist/paddle_install_dir', 'zip', root_dir='paddle_install_dir')"
echo BUILD INFERENCE LIBRARY COMPLETE
goto :END
:Rest_env
echo "Reset Build Environment ..."
taskkill /f /im cmake.exe 2>NUL
taskkill /f /im msbuild.exe 2>NUL
taskkill /f /im git.exe 2>NUL
taskkill /f /im cl.exe 2>NUL
taskkill /f /im lib.exe 2>NUL
taskkill /f /im git-remote-https.exe 2>NUL
taskkill /f /im vctip.exe 2>NUL
goto:eof
:Build
set build_times=1
:build_thirdparty
echo Build %BUILD_TYPE% Third Party Libraries, Round : %build_times%
echo msbuild /m /p:Configuration=Release third_party.vcxproj ^>^> build_thirdparty_%build_times%.log
msbuild /m /p:Configuration=Release third_party.vcxproj >> build_thirdparty_%build_times%.log
IF %ERRORLEVEL% NEQ 0 (
echo Build %BUILD_TYPE% Third Party Libraries, Round : %build_times% Failed!
set /a build_times=%build_times%+1
if %build_times% GTR %RETRY_TIMES% (
goto :FAILURE
) else (
goto :build_thirdparty
)
)
set build_times=1
:build_paddle
echo Build %BUILD_TYPE% Paddle Solutions, Round : %build_times%
echo msbuild /m /p:Configuration=Release paddle.sln ^>^> build_%build_times%.log
msbuild /m /p:Configuration=Release paddle.sln >> build_%build_times%.log
IF %ERRORLEVEL% NEQ 0 (
echo Build %BUILD_TYPE% Paddle Solutions, Round : %build_times% Failed!
set /a build_times=%build_times%+1
if %build_times% GTR %RETRY_TIMES% (
goto :FAILURE
) else (
goto :build_paddle
)
)
goto:eof
:FAILURE
echo BUILD FAILED
exit /b 1
:END
echo BUILD SUCCESSFULLY
ENDLOCAL
+19
View File
@@ -0,0 +1,19 @@
############# the scripts for bulk publish package on windows platform ################
# Usage: please use # to comment, use space or ; to separate multiple variables
# Generally, you only need to change CUDA_PATH and PYTHON_PATH to publish package
PADDLE_VERSION=2.0.0-alpha0
BRANCH=v2.0.0-alpha0
http_proxy=#please edit your proxy#
https_proxy=#please edit your proxy#
# Just for example, please set by your windows environment
vcvarsall_dir="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat"
PYTHON3_PATH=C:\Python37
CUDA_PATH="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0" "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0"
PYTHON_PATH=C:\Python37
@@ -0,0 +1,63 @@
@ECHO OFF
for /f "eol=# delims== tokens=1,2" %%i in (config.ini) do (
set %%i=%%j
)
set "source_path=%1"
if "%source_path%"=="" (
set /p source_path="Please input the dst path : =======>"
)
if not exist %source_path% mkdir %source_path%
cd /d %source_path%
if %errorlevel% NEQ 0 GOTO END
echo "begin to download the source code from https://github.com/paddlepaddle/paddle"
git clone https://github.com/PaddlePaddle/Paddle
cd Paddle
git checkout %BRANCH%
rem sed -i "s/@PADDLE_VERSION@/%PADDLE_VERSION%/g" paddle\fluid\framework\commit.h.in
rem sed -i "s/add_definitions(-DPADDLE_VERSION=\${PADDLE_VERSION})//g" cmake\version.cmake
echo "download done!!!"
cd ..
set start_path=%~dp0
echo %start_path%
echo Init Visual Studio Env
call %vcvarsall_dir% amd64
rem source_path PYTHON_DIR WITH_GPU WITH_MKL ON_INFER PADDLE_VERSION BATDIR CUDA_DIR
rem ==============build GPU============
for /D %%i in ( %CUDA_PATH% ) do (
for /D %%j in ( %PYTHON_PATH% ) do (
call %start_path%build.bat %source_path% %%j ON ON OFF %PADDLE_VERSION% %start_path% %%i
call %start_path%build.bat %source_path% %%j ON OFF OFF %PADDLE_VERSION% %start_path% %%i
)
rem ===build inference library===
call %start_path%build.bat %source_path% %PYTHON3_PATH% ON ON ON %PADDLE_VERSION% %start_path% %release_dir% %%i
call %start_path%build.bat %source_path% %PYTHON3_PATH% ON OFF ON %PADDLE_VERSION% %start_path% %release_dir% %%i
)
rem ==============build CPU=============
for /D %%j in ( %PYTHON_PATH% ) do (
call %start_path%build.bat %source_path% %%j OFF ON OFF %PADDLE_VERSION% %start_path% NEEDLESS
call %start_path%build.bat %source_path% %%j OFF OFF OFF %PADDLE_VERSION% %start_path% NEEDLESS
)
rem ===build inference library===
call %start_path%build.bat %source_path% %PYTHON3_PATH% OFF ON ON %PADDLE_VERSION% %start_path% %release_dir% NEEDLESS
call %start_path%build.bat %source_path% %PYTHON3_PATH% OFF OFF ON %PADDLE_VERSION% %start_path% %release_dir% NEEDLESS
:END
rem reset environment variable
for /f "eol=# delims== tokens=1,2" %%i in (config.ini) do (
set %%i=
)