|
1 | 1 | # Design Doc: Concurrent Programming with Fluid |
2 | 2 |
|
3 | | -With PaddlePaddle Fluid, users describe a program other than a model. The program is a [`ProgramDesc`](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/framework.proto) protobuf message. TensorFlow/MxNet/Caffe2 applications generate protobuf messages too, but their protobuf messages represent the model, a graph of operators, but not the program that trains/uses the model. |
| 3 | +With PaddlePaddle Fluid, users describe a program other than a model. The program is a [`ProgramDesc`](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/fluid/framework/framework.proto) protobuf message. TensorFlow/MxNet/Caffe2 applications generate protobuf messages too, but their protobuf messages represent the model, a graph of operators, but not the program that trains/uses the model. |
4 | 4 |
|
5 | 5 | Many know that when we program TensorFlow, we can specify the device on which each operator runs. This allows us to create a concurrent/parallel AI application. An interesting questions is **how does a `ProgramDesc` represents a concurrent program?** |
6 | 6 |
|
@@ -28,19 +28,19 @@ The following table compares concepts in Fluid and Go |
28 | 28 | <tr> |
29 | 29 | <td>control-flow and built-in functions </td> |
30 | 30 | <td> |
31 | | -<a href="https://github.com/PaddlePaddle/Paddle/tree/develop/paddle/operators">intrinsics/operators</a></td> |
| 31 | +<a href="https://github.com/PaddlePaddle/Paddle/tree/develop/paddle/fluid/operators">intrinsics/operators</a></td> |
32 | 32 | <td></td> |
33 | 33 | </tr> |
34 | 34 | <tr> |
35 | 35 | <td>goroutines, channels </td> |
36 | 36 | <td> |
37 | | -<a href="https://github.com/PaddlePaddle/Paddle/tree/develop/paddle/framework/thread_pool.h">class ThreadPool</a></td> |
| 37 | +<a href="https://github.com/PaddlePaddle/Paddle/tree/develop/paddle/fluid/framework/thread_pool.h">class ThreadPool</a></td> |
38 | 38 | <td></td> |
39 | 39 | </tr> |
40 | 40 | <tr> |
41 | 41 | <td>runtime </td> |
42 | 42 | <td> |
43 | | -<a href="https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/executor.h">class Executor</a></td> |
| 43 | +<a href="https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/fluid/framework/executor.h">class Executor</a></td> |
44 | 44 | <td></td> |
45 | 45 | </tr> |
46 | 46 | </tbody> |
@@ -78,7 +78,7 @@ message ProgramDesc { |
78 | 78 | } |
79 | 79 | ``` |
80 | 80 |
|
81 | | -Then, the default `main` function calls `fluid.run()`, which creates an instance of the [`class Executor`](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/executor.h) and calls `Executor.Run(block[0])`, where `block[0]` is the first and only block defined in above `ProgramDesc` message. |
| 81 | +Then, the default `main` function calls `fluid.run()`, which creates an instance of the [`class Executor`](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/fluid/framework/executor.h) and calls `Executor.Run(block[0])`, where `block[0]` is the first and only block defined in above `ProgramDesc` message. |
82 | 82 |
|
83 | 83 | The default `main` function is defined as follows: |
84 | 84 |
|
@@ -146,7 +146,7 @@ An explanation of the above program: |
146 | 146 |
|
147 | 147 | - `fluid.k8s` is a package that provides access to Kubernetes API. |
148 | 148 | - `fluid.k8s.get_worker_addrs` returns the list of IP and ports of all pods of the current job except for the current one (the master pod). |
149 | | -- `fluid.tensor_array` creates a [tensor array](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/lod_tensor_array.h). `fluid.parallel_for` creates a `ParallelFor` intrinsic, which, when executed, |
| 149 | +- `fluid.tensor_array` creates a [tensor array](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/fluid/framework/lod_tensor_array.h). `fluid.parallel_for` creates a `ParallelFor` intrinsic, which, when executed, |
150 | 150 |
|
151 | 151 | 1. creates `len(L)` scopes, each for the concurrent running of the sub-block (block 1 in this case), and initializes a variable named "index" in the scope to an integer value in the range `[0, len(L)-1]`, and |
152 | 152 | 2. creates `len(L)` threads by calling into the `ThreadPool` singleton, each thread |
@@ -175,7 +175,7 @@ where |
175 | 175 | 1. listens on the current pod's IP address, as returned by `fliud.k8s.self_addr()`, |
176 | 176 | 2. once a connection is established, |
177 | 177 | 1. creates a scope of two parameters, "input" and "output", |
178 | | - 2. reads a [Fluid variable](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/variable.h) and saves it into "input", |
| 178 | + 2. reads a [Fluid variable](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/fluid/framework/variable.h) and saves it into "input", |
179 | 179 | 3. creates an Executor instance and calls `Executor.Run(block)`, where the block is generated by running the lambda specified as the second parameter of `fluid.listen_and_do`. |
180 | 180 |
|
181 | 181 | ## Summarization |
|
0 commit comments