Skip to content
This repository was archived by the owner on Jan 26, 2026. It is now read-only.

Commit dfa512c

Browse files
committed
some cleanup/comments
1 parent caaf2f1 commit dfa512c

Some content is hidden

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

54 files changed

+378
-17
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ mpirun -n $N python -m pytest test
3535
DDPT_CW=0 mpirun -n $N python -m pytest test
3636
```
3737

38+
If DDPT_MPI_SPAWN is set it spawns the provided number of MPI processes.
39+
By default new processes launch python executing a worker loop.
40+
This requires setting PYTHON_EXE.
41+
Alternatively DDPT_MPI_EXECUTABLE and DDPT_MPI_EXE_ARGS are used.
42+
Additionally DDPT_MPI_HOSTS can be used to control the host to use for spawning processes.
43+
3844
## Running
3945
```python
4046
import ddptensor as dt

src/Creator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
C++ representation of the array-API's creation functions.
3+
*/
4+
15
#include "ddptensor/Creator.hpp"
26
#include "ddptensor/DDPTensorImpl.hpp"
37
#include "ddptensor/Deferred.hpp"

src/Deferred.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22

3+
/*
4+
Creation/destruction of Deferreds.
5+
Implementation of worker loop processing deferred objects.
6+
This worker loop is executed in a separate thread until the system
7+
gets shut down.
8+
*/
9+
310
#include "include/ddptensor/Deferred.hpp"
411
#include "include/ddptensor/Mediator.hpp"
512
#include "include/ddptensor/Registry.hpp"
@@ -14,20 +21,29 @@
1421
#include <iostream>
1522
#include <unordered_set>
1623

24+
// thread-safe FIFO queue holding deferred objects
1725
static tbb::concurrent_bounded_queue<Runable::ptr_type> _deferred;
1826

27+
// add a deferred object to the queue
1928
void push_runable(Runable::ptr_type &&r) { _deferred.push(std::move(r)); }
2029

30+
// if needed, object/promise is broadcasted to worker processes
31+
// (for controller/worker mode)
2132
void _dist(const Runable *p) {
2233
if (getTransceiver()->is_cw() && getTransceiver()->rank() == 0)
2334
getMediator()->to_workers(p);
2435
}
2536

37+
// create a enriched future
2638
Deferred::future_type Deferred::get_future() {
2739
return {std::move(promise_type::get_future().share()), _guid, _dtype, _rank,
2840
_balanced};
2941
}
3042

43+
// defer a tensor-producing computation by adding it to the queue.
44+
// return a future for the resulting tensor.
45+
// set is_global to false if result is a local temporary which does not need a
46+
// guid
3147
Deferred::future_type defer_tensor(Runable::ptr_type &&_d, bool is_global) {
3248
Deferred *d = dynamic_cast<Deferred *>(_d.get());
3349
if (!d)
@@ -42,6 +58,7 @@ Deferred::future_type defer_tensor(Runable::ptr_type &&_d, bool is_global) {
4258
return f;
4359
}
4460

61+
// defer a global tensor producer
4562
void Deferred::defer(Runable::ptr_type &&p) {
4663
defer_tensor(std::move(p), true);
4764
}
@@ -50,6 +67,15 @@ void Runable::defer(Runable::ptr_type &&p) { push_runable(std::move(p)); }
5067

5168
void Runable::fini() { _deferred.clear(); }
5269

70+
// process promises as they arrive through calls to defer
71+
// This is run in a separate thread until shutdon is requested.
72+
// Shutdown is indicated by a Deferred object which evaluates to false.
73+
// The loop repeatedly creates MLIR functions for jit-compilation by letting
74+
// Deferred objects add their MLIR code until an object can not produce MLIR
75+
// but wants immediate execution (indicated by generate_mlir returning true).
76+
// When execution is needed, the function signature (input args, return
77+
// statement) is finalized, the function gets compiled and executed. The loop
78+
// completes by calling run() on the requesting object.
5379
void process_promises() {
5480
bool done = false;
5581
jit::JIT jit;

src/EWBinOp.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22

3+
/*
4+
Elementwise binary ops.
5+
*/
6+
37
#include "ddptensor/EWBinOp.hpp"
48
#include "ddptensor/CollComm.hpp"
59
#include "ddptensor/Creator.hpp"
@@ -15,6 +19,7 @@
1519
#include <mlir/Dialect/Shape/IR/Shape.h>
1620
#include <mlir/IR/Builders.h>
1721

22+
#if 0
1823
// #######################################################################################
1924
// The 2 operators/tensors can have shifted partitions, e.g. local data might
2025
// not be the same on a and b. This means we need to copy/communicate to bring
@@ -43,7 +48,6 @@
4348
// above regions and apply the op. All buffers/views get linearized/flattened.
4449
// #######################################################################################
4550

46-
#if 0
4751
namespace x {
4852

4953
// @return true if operation returs bool, false otherwise

src/EWUnyOp.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
3+
/*
4+
Elementwise unary ops.
5+
*/
6+
17
#include "ddptensor/EWUnyOp.hpp"
28
#include "ddptensor/DDPTensorImpl.hpp"
39
#include "ddptensor/Factory.hpp"

src/Factory.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
3+
/*
4+
A factory producing runnable objects.
5+
Implementation for registering factories.
6+
*/
7+
18
#include "ddptensor/Factory.hpp"
29

310
std::vector<Factory::ptr_type> s_factories(FACTORY_LAST);

src/IEWBinOp.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
3+
/*
4+
Inplace elementwise binary ops.
5+
*/
6+
17
#include "ddptensor/IEWBinOp.hpp"
28
#include "ddptensor/Creator.hpp"
39
#include "ddptensor/DDPTensorImpl.hpp"

src/IO.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
3+
/*
4+
I/O ops.
5+
*/
6+
17
#include "ddptensor/IO.hpp"
28
#include "ddptensor/Factory.hpp"
39
#include "ddptensor/SetGetItem.hpp"

src/LinAlgOp.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
3+
/*
4+
Linalg ops.
5+
*/
6+
17
#include <mpi.h>
28
//#include <mkl.h>
39
#include "ddptensor/DDPTensorImpl.hpp"

src/MPIMediator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22

3+
/*
4+
A high-level mediation between processes/ranks implemented on top of MPI.
5+
*/
6+
37
#include <iostream>
48
#include <mpi.h>
59
#include <mutex>

0 commit comments

Comments
 (0)