Skip to content

Commit 9f68209

Browse files
committed
Add Design section to README.md
ghstack-source-id: a497cb3 Pull Request resolved: #16
1 parent 8ef4ad4 commit 9f68209

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

.github/csprng_architecture.png

90.6 KB
Loading

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dist/
22
build/
33
pytorch_csprng.egg-info/
4+
.idea

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,32 @@ CSPRNG is a [PyTorch C++/CUDA extension](https://pytorch.org/tutorials/advanced/
44

55
[![CircleCI](https://circleci.com/gh/pytorch/csprng.svg?style=shield&circle-token=64701692dd7f13f31019612289f0200fdb661dc2)](https://circleci.com/gh/pytorch/csprng)
66

7+
## Design
8+
9+
CSPRNG generates a random 128-bits key on CPU using one of its generators and runs
10+
[AES128](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard) in [CTR mode](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_(CTR))
11+
mode either on CPU or CUDA to generate random 128 bits state and apply transformation function to map it to target tensor values.
12+
This approach is based on [Parallel Random Numbers: As Easy as 1, 2, 3(John K. Salmon, Mark A. Moraes, Ron O. Dror, and David E. Shaw, D. E. Shaw Research)](http://www.thesalmons.org/john/random123/papers/random123sc11.pdf).
13+
It makes CSPRNG both crypto-secure and parallel on CUDA and CPU.
14+
15+
![CSPRNG architecture](.github/csprng_architecture.png)
16+
17+
Advantages:
18+
19+
- A user can choose either seed-based(for testing) or random device based(fully crypto-secure) generators
20+
- One generator instance for both CPU and CUDA tensors(because the encryption key is always generated on CPU)
21+
- CPU random number generation is also parallel(unlike standard PyTorch CPU generator).
22+
723
## Featues
824

925
CSPRNG exposes four methods to create crypto-secure and non-crypto-secure PRNGs:
1026

11-
| PRNG | Is crypto-secure? | Has seed? |
12-
|-------------------------------------------|-------------------|-----------|
13-
| create_random_device_generator | yes | no |
14-
| create_random_device_generator_with_token | yes | no |
15-
| create_mt19937_generator | no | yes |
16-
| create_mt19937_generator_with_seed | no | yes |
27+
| Method to create PRNG | Is crypto-secure? | Has seed? | Underlying implementation |
28+
|----------------------------------------------------------|-------------------|-----------|--------------------------------------------------------------------------------------------------------------------------------|
29+
| create_random_device_generator() | yes | no | [std::random_device](https://en.cppreference.com/w/cpp/numeric/random/random_device) created with default constructor |
30+
| create_random_device_generator_with_token(token: string) | yes | no | [std::random_device](https://en.cppreference.com/w/cpp/numeric/random/random_device) created with a token(e.g. "/dev/urandom") |
31+
| create_mt19937_generator() | no | yes | [std::mt19937](https://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine) created with default constructor |
32+
| create_mt19937_generator_with_seed(seed: int) | no | yes | [std::mt19937](https://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine) created with a seed |
1733

1834
The following list of methods supports all forementioned PRNGs:
1935

0 commit comments

Comments
 (0)