Skip to content

Commit 1ad72d7

Browse files
authored
SPU 0.2.x (secretflow#20)
* Sync SPU 0.2.x
1 parent e3c3f67 commit 1ad72d7

File tree

526 files changed

+39306
-18641
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

526 files changed

+39306
-18641
lines changed

.bazelrc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ build --enable_platform_specific_config
66

77
build --cxxopt=-std=c++17
88
build --host_cxxopt=-std=c++17
9-
build --linkopt -fvisibility=hidden
109

1110

1211
test --keep_going
@@ -19,6 +18,11 @@ build:macos --features=-supports_dynamic_linker
1918
build:macos --cxxopt -Wno-deprecated-enum-enum-conversion
2019
build:macos --cxxopt -Wno-deprecated-anon-enum-enum-conversion
2120
build:macos --macos_minimum_os=11.0
21+
build:macos --host_macos_minimum_os=11.0
22+
23+
# static link libstdc++ & libgcc on Linux
24+
build:linux --action_env=BAZEL_LINKOPTS=-static-libstdc++:-static-libgcc
25+
build:linux --action_env=BAZEL_LINKLIBS=-l%:libstdc++.a:-l%:libgcc.a
2226

2327
build:asan --strip=never
2428
build:asan --copt -fno-sanitize-recover=all

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.2.0
1+
5.1.1

BUILD.bazel

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2022 Ant Group Co., Ltd.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@
99
## staging
1010
> please add your unrelease change here.
1111
12+
## 20220905
13+
- [SPU] 0.2.4 release
14+
- [bugfix] Fix Tensorflow example
15+
- [miscs] Performance improvements
16+
17+
## 20220822
18+
- [SPU] 0.2.1 release
19+
- [Feature] Add compiler cache
20+
- [Feature] Support bc22-pcg psi
21+
- [API] Refactor psi api
22+
- [miscs] Various performance improvements
23+
24+
## 20220727
25+
- [SPU] 0.1.1 release
26+
- [API] Added rsqrt support
27+
- [bugfix] Fixed some crashes and wrong answers
28+
29+
1230
## 20220527
1331
- [SPU] 0.1.0 release
1432
- [API] Add exp/log approximation configurations.

CONTRIBUTING.md

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contributing
1+
# Contribution guidelines
22

33
## Contributor License Agreement
44

@@ -31,6 +31,90 @@ The compiler portion of the project follows [MLIR style](https://mlir.llvm.org/g
3131
* Developer must write unit-test (line coverage must be greater than 80%), tests should be deterministic.
3232
* Read awesome [Abseil Tips](https://abseil.io/tips/)
3333

34+
## Build
35+
36+
### Prerequisite
37+
38+
#### Docker
39+
```sh
40+
## start container
41+
docker run -d -it --name spu-gcc11-anolis-dev-$(whoami) \
42+
--mount type=bind,source="$(pwd)",target=/home/admin/dev/ \
43+
-w /home/admin/dev \
44+
--cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
45+
--cap-add=NET_ADMIN \
46+
--privileged=true \
47+
secretflow/secretflow-gcc11-anolis-dev:latest
48+
49+
# attach to build container
50+
docker exec -it spu-gcc11-anolis-dev-$(whoami) bash
51+
```
52+
53+
#### Linux
54+
55+
```sh
56+
Install gcc>=11.2, cmake>=3.18, ninja, nasm>=2.15, python==3.8, bazel==5.1.1
57+
58+
python3 -m pip install -r requirements.txt
59+
```
60+
61+
#### macOS
62+
63+
```sh
64+
# macOS >= 11, Xcode >=13.0
65+
66+
# Install Xcode
67+
https://apps.apple.com/us/app/xcode/id497799835?mt=12
68+
69+
# Select Xcode toolchain version
70+
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
71+
72+
# Install homebrew
73+
https://brew.sh/
74+
75+
# Install dependencies
76+
brew install bazel cmake ninja nasm
77+
78+
# Extra setup step for Apple Silicon users
79+
conda install grpcio
80+
81+
# Install python dependencies
82+
pip install -r requirements.txt
83+
```
84+
85+
### Build & UnitTest
86+
87+
``` sh
88+
89+
# build as debug
90+
bazel build //... -c dbg
91+
92+
# build as release
93+
bazel build //... -c opt
94+
95+
# test
96+
bazel test //...
97+
98+
# [optional] build & test with ASAN or UBSAN, for macOS users please use configs with macOS prefix
99+
bazel test //... --config=[macos-]asan
100+
bazel test //... --config=[macos-]ubsan
101+
```
102+
103+
### Bazel build options
104+
105+
- `--define gperf=on` enable gperf
106+
- `--define tracelog=on` enable link trace log.
107+
108+
### Build docs
109+
110+
```sh
111+
# prerequisite
112+
pip install -U docs/requirements.txt
113+
114+
cd docs & make html # html docs will be in docs/_build/html
115+
```
116+
117+
34118
## Release cycle
35119

36120
SPU recommends users "live-at-head" like [abseil-cpp](https://github.com/abseil/abseil-cpp), just like abseil, spu also provide Long Term Support Releases to which we backport fixes for severe bugs.

INSTALLATION.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Installation Guidelines
2+
3+
## Environment
4+
5+
### Linux
6+
7+
SPU has been tested with the following settings:
8+
9+
- Anolis OS 8.4 or later
10+
- python3.8
11+
- 8c16g
12+
13+
### MacOS
14+
15+
We have conducted some successful preliminary testings on macOS Monterey 12.4 with Intel processors and Apple Silicon.
16+
17+
### Docker Image
18+
19+
Please check [official Docker image](https://registry.hub.docker.com/r/secretflow/secretflow-gcc11-anolis-dev).
20+
21+
22+
## Binaries
23+
24+
### From PyPI
25+
26+
You could install SPU via the [official PyPI package](https://pypi.org/project/spu/)
27+
28+
```bash
29+
pip install spu
30+
```
31+
32+
33+
### From Source
34+
35+
At the root of repo, run
36+
37+
```bash
38+
sh build_and_packaging.sh -i
39+
```

README.md

Lines changed: 7 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,99 +4,21 @@
44

55
SPU (Secure Processing Unit) aims to be a `provable`, `measurable` secure computation device, which provides computation ability while keeping your private data protected.
66

7-
## Project status
7+
SPU could be treated as a programmable device, it's not designed to be used directly. Normally we use SecretFlow framework, which use SPU as the underline secure computing device.
88

99
Currently, we mainly focus on `provable` security. It contains a secure runtime that evaluates [XLA](https://www.tensorflow.org/xla/operation_semantics)-like tensor operations, which use [MPC](https://en.wikipedia.org/wiki/Secure_multi-party_computation) as the underline evaluation engine to protect privacy information.
1010

11-
## Contents
12-
- [Documentation](https://secretflow.readthedocs.io)
13-
- [Roadmap](TBD)
14-
- [Build and test](#Build)
15-
- [FAQ](#FAQ)
16-
17-
## Build
18-
19-
### Prerequisite
20-
21-
#### Docker
22-
```sh
23-
## start container
24-
docker run -d -it --name spu-gcc11-anolis-dev-$(whoami) \
25-
--mount type=bind,source="$(pwd)",target=/home/admin/dev/ \
26-
-w /home/admin/dev \
27-
--cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
28-
--cap-add=NET_ADMIN \
29-
--privileged=true \
30-
registry.hub.docker.com/secretflow/spu-gcc11-anolis-dev:latest
31-
32-
# attach to build container
33-
docker exec -it spu-gcc11-anolis-dev-$(whoami) bash
34-
```
35-
36-
#### Linux
37-
38-
```sh
39-
Install gcc>=11.2, cmake>=3.18, ninja, nasm>=2.15, python==3.8, bazel==5.1.1
40-
41-
python3 -m pip install -r docker/requirements.txt
42-
```
43-
44-
#### macOS
45-
46-
```sh
47-
# macOS >= 11, Xcode >=13.0
48-
49-
# Install Xcode
50-
https://apps.apple.com/us/app/xcode/id497799835?mt=12
51-
52-
# Select Xcode toolchain version
53-
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
54-
55-
# Install homebrew
56-
https://brew.sh/
57-
58-
# Install dependencies
59-
brew install bazel cmake ninja nasm
60-
61-
# Install python dependencies
62-
python3 -m pip install -r docker/requirements.txt
63-
```
64-
65-
### Build & UnitTest
66-
67-
``` sh
68-
69-
# build as debug
70-
bazel build //... -c dbg
71-
72-
# build as release
73-
bazel build //... -c opt
74-
75-
# test
76-
bazel test //...
77-
78-
# [optional] build & test with ASAN or UBSAN, for macOS users please use configs with macOS prefix
79-
bazel test //... --config=[macos-]asan
80-
bazel test //... --config=[macos-]ubsan
81-
```
82-
83-
84-
### Build docs
85-
86-
```sh
87-
# prerequisite
88-
pip install -U sphinx
11+
SPU python package also contains a simple distributed module to demo SPU usage, but it's **NOT designed for production** due to system security and performance concerns, please **DO NOT** use it directly in production.
8912

90-
cd docs & make html # html docs will be in docs/_build/html
91-
```
13+
## Contribution Guidelines
9214

93-
## FAQ
15+
If you would like to contribute to SPU, please check [Contribution guidelines](CONTRIBUTING.md).
9416

95-
> How can I use SPU?
17+
This documentation also contains instructions for [build and testing](CONTRIBUTING.md#build).
9618

97-
SPU could be treated as a programmable device, it's not designed to be used directly. Normally we use SecretFlow framework, which use SPU as the underline secure computing device.
19+
## Installation Guidelines
9820

99-
SPU python package also contains a simple distributed module to demo SPU usage, but it's **NOT designed for production** due to system security and performance concerns, please **DO NOT** use it directly in production.
21+
Please follow [Installation Guidelines](INSTALLATION.md) to install SPU.
10022

10123
## Acknowledgement
10224

WORKSPACE

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ spu_deps()
66

77
#
88
# yasl
9+
# Warning: SPU relies on yasl to bring in common 3p libraries.
10+
# Please make sure yasl_deps are called right after spu_deps.
911
#
1012
load("@yasl//bazel:repositories.bzl", "yasl_deps")
1113

@@ -55,7 +57,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
5557
# https://github.com/hedronvision/bazel-compile-commands-extractor
5658
git_repository(
5759
name = "hedron_compile_commands",
58-
commit = "30149bdadf7b1d0b0367592bfb4864318202765d",
60+
commit = "57046dba8d60f819887ea81933ed90f8e23a458a",
5961
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
6062
shallow_since = "1644967664 -0800",
6163
)

bazel/BUILD.bazel

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2022 Ant Group Co., Ltd.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
package(default_visibility = ["//visibility:public"])
216

317
config_setting(

bazel/easyloggingpp.BUILD

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2022 Ant Group Co., Ltd.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
load("@spulib//bazel:spu.bzl", "spu_cmake_external")
216

317
package(default_visibility = ["//visibility:public"])

0 commit comments

Comments
 (0)