Skip to content

Commit 960bf22

Browse files
init
Signed-off-by: Yanheng Lu <yanheng.lyh@alibaba-inc.com>
1 parent 0904508 commit 960bf22

569 files changed

Lines changed: 11361659 additions & 0 deletions

File tree

Some content is hidden

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

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<h1 align="center">CHAM</h1>
2+
<h4 align="center">A Customized Homomorphic Encryption Accelerator for Fast Matrix-Vector Product</h4>
3+
4+
The __CHAM__ project is initiated by Alibaba DAMO Academy CTL and Ant Group's AntChain.
5+
6+
___CHAM___ is a customized homomorphic encryption accelerator for fast matrix-vector product. Homomorphic encryption (HE), enabling computation on encrypted data, suffers from poor performance due to enlarged data size and exploded amount of computation. Existing HE accelerators either target small HE operations or fail to support fast-evolving HE algorithms. To better support various privacy-preserving applications (e.g., logistic regression and neural-network inference), we propose CHAM for high-performance matrix-vector product, which can be easily extended to 2D/3D convolutions.
7+
8+
The code in this repository is released by Alibaba DAMO Academy CTL and Ant Group's AntChain under MIT License.
9+
10+
The distribution is developed as part of our DAC2023 paper called *"CHAM: A Customized Homomorphic Encryption Accelerator for Fast Matrix-Vector Product"*. This distribution is an open-source version of our commercial accelerator and not ready for production use.
11+
12+
13+
## Table of contents
14+
15+
- [Directory structure](#directory-structure)
16+
- [Build guide](#build-guide)
17+
- [License](#license)
18+
19+
## Directory structure
20+
21+
The directory structure is as follows:
22+
23+
* [__src__](src): RTL source files
24+
* [__include__](include): include files
25+
* [__sim__](sim): simulation environment
26+
* [__tv__](tv): test vectors
27+
* [__xilinx_vcs_lib__](xilinx_vcs_lib): xilinx vcs simulation library
28+
29+
30+
## Build guide
31+
32+
1. Generate xilinx vcs lib in ./xilinx_vcs_lib
33+
2. Modify sim/vcs/tb_top.sh line 48 to your vcs path
34+
3. cd sim
35+
4. make clean //remove the previous run_dir
36+
5. ./run_case <test name>//test name is showing below in Test cases
37+
test_stg_0_0 test single stage at stage 0, and test only ksk ram init path
38+
test_stg_0_1 test single stage at stage 0, and test only preprocess init path
39+
test_stg_1 test single stage at stage 1
40+
test_stg_2 test single stage at stage 2
41+
test_stg_3 test single stage at stage 3
42+
test_stg_4 test single stage at stage 4
43+
test_stg_5 test single stage at stage 5
44+
test_stg_6 test single stage at stage 6
45+
test_stg_7 test single stage at stage 7
46+
test_stg_8 test single stage at stage 8
47+
test_stg_9 test single stage at stage 9
48+
test_stg_10 test single stage at stage 10
49+
test_row test all stages in a row
50+
test_full_no_uram_4x4096 test full case, the test vector is 4x4096. we use testbench to init ksk ram instead of designtest_full_4x4096 test full case, the test vector is 4x4096.
51+
test_full_4x4096 test full case, the test vector is 4x4096.
52+
53+
## License
54+
55+
[MIT License](LICENSE)
56+
57+
This product contains several third-party components under other open source licenses.
58+
59+
src/axi/axi_read_master.sv BSD-2-Clause Vitis-Tutorials
60+
src/axi/axi_write_master.sv BSD-2-Clause Vitis-Tutorials
61+
src/axi/counter.sv BSD-2-Clause Vitis-Tutorials

include/addx_defines.vh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`timescale 1ns/1ps

include/common_defines.vh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//////////////////////////////////////////////////
2+
// Author: Zhang Yichi (changlv)
3+
// Email: changlv.zyc@alibaba-inc.com
4+
//
5+
// Project Name: MVP
6+
// Module Name: common_defines
7+
// Modify Date: 07/08/2021 13:00
8+
// Description: Attributes of common modules (modadd, modsub, etc.)
9+
//////////////////////////////////////////////////
10+
11+
`ifndef __COMMON_DEFINES_VH__
12+
`define __COMMON_DEFINES_VH__
13+
14+
`timescale 1ns/1ps
15+
16+
//`define SIMULATION
17+
`define FPGA
18+
19+
20+
`define COMMON_DATA_LENGTH 4096
21+
`define COMMON_BRAM_DELAY 1 // delay of Block RAM
22+
`define COMMON_URAM_DELAY 3 // delay of Ultra RAM
23+
`define COMMON_MODMUL_DELAY 4 // delay of ModMul module
24+
`define COMMON_MODADD_DELAY 1 // delay of ModAdd module
25+
`define COMMON_MODSUB_DELAY 1 // delay of ModSub module
26+
`define COMMON_MODSUBRED_DELAY 2 // delay of ModSubRed module
27+
28+
`endif // __COMMON_DEFINES_VH__

include/dp_defines.vh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//////////////////////////////////////////////////
2+
// Author: Gu Zhen (jingchen)
3+
// Email: guzhen.gz@alibaba-inc.com
4+
//
5+
// Project Name: MVP
6+
// Module Name: dp_defines
7+
// Modify Date: 12/03/2022 13:00
8+
// Description: Attributes of dp modules
9+
//////////////////////////////////////////////////
10+
11+
`ifndef __DP_DEFINES_VH__
12+
`define __DP_DEFINES_VH__
13+
14+
`timescale 1ns/100ps
15+
16+
//`define SIMULATION
17+
`define FPGA
18+
19+
`define COMMON_DATA_LENGTH 4096
20+
`define COMMON_BRAM_DELAY 1 // delay of Block RAM
21+
`define COMMON_URAM_DELAY 1 // delay of Ultra RAM
22+
`define COMMON_MODMUL_DELAY 4 // delay of ModMul module
23+
`define COMMON_MODADD_DELAY 1 // delay of ModAdd module
24+
`define COMMON_MODSUB_DELAY 1 // delay of ModSub module
25+
`define COMMON_MODSUBRED_DELAY 2 // delay of ModSubRed module
26+
`define COMMON_MODMULADD_DELAY 4 // delay of ModMulAdd module
27+
`define DP_MADD_PIP_DELAY 5
28+
`define NUM_BASE_BANK 8
29+
`define COE_WIDTH_0 35
30+
`define COE_WIDTH_1 35
31+
`define COE_WIDTH_2 39
32+
`define N 4096
33+
`define BRAM_DEPTH 512
34+
`define Q0 17314086913 // Q35 0
35+
`define Q1 17180393473 // Q35 1
36+
`define Q2 274886295553 // Q39
37+
`define Qinv0 17309859841
38+
`define Qinv1 17176199041
39+
`define Qinv2 274819184641
40+
`define MAX_N_SPLIT 4
41+
`define NUM_CTXT 2
42+
`define NUM_MOD 3
43+
`endif // __DP_DEFINES_VH__

include/monox_defines.vh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`timescale 1ns / 1ps

include/mux_defines.vh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`timescale 1ns / 1ps

include/ntt_intt_defines.vh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//////////////////////////////////////////////////
2+
// Engineer: Chen Zhaohui (xinming)
3+
// Email: chenzhaohui.czh@alibaba-inc.com
4+
//
5+
// Project Name: MVP
6+
// Module Name: ntt_intt_defines
7+
// Modify Date: 07/28/2021 11:10
8+
9+
// Description: Define timescale and some common params
10+
//////////////////////////////////////////////////
11+
12+
`include "common_defines.vh"
13+
`ifndef __NTT_INTT_DEFINES_VH__
14+
`define __NTT_INTT_DEFINES_VH__
15+
16+
`define N 4096
17+
`define Q0 17314086913 // Q35 0
18+
`define Q1 17180393473 // Q35 1
19+
`define Q2 274886295553 // Q39
20+
21+
`endif // __NTT_INTT_DEFINES_VH__

include/vpu2_defines.vh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//////////////////////////////////////////////////
2+
// Author: Zhang Yichi (changlv)
3+
// Email: changlv.zyc@alibaba-inc.com
4+
//
5+
// Project Name: MVP
6+
// Module Name: vpu2_defines
7+
// Modify Date: 07/09/2021 16:30
8+
//
9+
// Description: Attributes and parameters of VPU2
10+
//////////////////////////////////////////////////
11+
12+
`ifndef __VPU2_DEFINES_VH__
13+
`define __VPU2_DEFINES_VH__
14+
15+
`define VPU2_DELAY (`COMMON_URAM_DELAY + `COMMON_MODMUL_DELAY + `COMMON_MODADD_DELAY)
16+
17+
`define VPU2_RD_BEGIN 0
18+
`define VPU2_WR_BEGIN (`VPU2_RD_BEGIN + `VPU2_DELAY)
19+
20+
`define VPU2_RD_END (`VPU2_RD_BEGIN + `COMMON_DATA_LENGTH)
21+
`define VPU2_WR_END (`VPU2_WR_BEGIN + `COMMON_DATA_LENGTH)
22+
23+
`define VPU2_BUSY_END (`VPU2_WR_END) // when state BUSY -> IDLE
24+
25+
`endif // __VPU2_DEFINES_VH__

include/vpu3_defines.vh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//////////////////////////////////////////////////
2+
// Author: Zhang Yichi (changlv)
3+
// Email: changlv.zyc@alibaba-inc.com
4+
//
5+
// Project Name: MVP
6+
// Module Name: VPU3
7+
// Modify Date: 07/14/2021 15:30
8+
//
9+
// Description: Attributes and parameters of VP3U
10+
//////////////////////////////////////////////////
11+
12+
`ifndef __VPU3_DEFINES_VH__
13+
`define __VPU3_DEFINES_VH__
14+
15+
`define VPU3_DELAY (`COMMON_BRAM_DELAY + `COMMON_MODADD_DELAY + `COMMON_MODSUBRED_DELAY + `COMMON_MODSUB_DELAY + `COMMON_MODMUL_DELAY + `COMMON_MODADD_DELAY)
16+
17+
`define VPU3_RD_BEGIN 0
18+
`define VPU3_RDA_BEGIN (`VPU3_RD_BEGIN + `COMMON_MODADD_DELAY + `COMMON_MODSUBRED_DELAY)
19+
`define VPU3_RDB_BEGIN (`VPU3_RD_BEGIN + `COMMON_MODADD_DELAY + `COMMON_MODSUBRED_DELAY + `COMMON_MODSUB_DELAY + `COMMON_MODMUL_DELAY)
20+
`define VPU3_RDC_BEGIN (`VPU3_RD_BEGIN + 0)
21+
`define VPU3_WR_BEGIN (`VPU3_RD_BEGIN + `VPU3_DELAY)
22+
23+
`define VPU3_RD_END (`VPU3_RD_BEGIN + `COMMON_DATA_LENGTH)
24+
`define VPU3_RDA_END (`VPU3_RDA_BEGIN + `COMMON_DATA_LENGTH)
25+
`define VPU3_RDB_END (`VPU3_RDB_BEGIN + `COMMON_DATA_LENGTH)
26+
`define VPU3_RDC_END (`VPU3_RDC_BEGIN + `COMMON_DATA_LENGTH)
27+
`define VPU3_WR_END (`VPU3_WR_BEGIN + `COMMON_DATA_LENGTH)
28+
29+
`define VPU3_BUSY_END (`VPU3_WR_END) // when state BUSY -> IDLE
30+
31+
`endif // __VPU3_DEFINES_VH__
32+

include/vpu4_defines.vh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//////////////////////////////////////////////////
2+
// Author: Zhang Yichi (changlv)
3+
// Email: changlv.zyc@alibaba-inc.com
4+
//
5+
// Project Name: MVP
6+
// Module Name: vpu4_defines
7+
// Modify Date: 07/14/2021 16:00
8+
// Description: Attributes and parameters of VPU4
9+
//////////////////////////////////////////////////
10+
11+
`ifndef __VPU4_DEFINES_VH__
12+
`define __VPU4_DEFINES_VH__
13+
14+
`define VPU4_DELAY (`COMMON_BRAM_DELAY + `COMMON_MODSUB_DELAY + `COMMON_MODMUL_DELAY)
15+
16+
`define VPU4_RD_BEGIN 0
17+
`define VPU4_WR_BEGIN (`VPU4_RD_BEGIN + `VPU4_DELAY)
18+
19+
`define VPU4_RD_END (`VPU4_RD_BEGIN + `COMMON_DATA_LENGTH)
20+
`define VPU4_WR_END (`VPU4_WR_BEGIN + `COMMON_DATA_LENGTH)
21+
22+
`define VPU4_BUSY_END (`VPU4_WR_END) // when state BUSY -> IDLE
23+
24+
`endif // __VPU4_DEFINES_VH__
25+

0 commit comments

Comments
 (0)