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

Commit f0434ba

Browse files
fschlimbtkarna
andauthored
adding examples (#22)
* adding examples and a new test * delete -> free; new -> aligned_alloc * updating imex --------- Co-authored-by: Tuomas Karna <tuomas.karna@intel.com>
1 parent eafba26 commit f0434ba

File tree

6 files changed

+76
-19
lines changed

6 files changed

+76
-19
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,28 @@ jobs:
122122
. $GITHUB_WORKSPACE/third_party/install/miniconda/etc/profile.d/conda.sh
123123
. $GITHUB_WORKSPACE/third_party/install/miniconda/bin/activate ddpt
124124
MLIRROOT=$GITHUB_WORKSPACE/third_party/install/llvm-mlir IMEXROOT=$GITHUB_WORKSPACE/third_party/install/imex python setup.py install
125+
DDPT_ROOT=`pip show -f ddptensor | grep Location | awk '{print $2}'`
126+
echo "DDPT_IDTR_SO=${DDPT_ROOT}/ddptensor/libidtr.so" >> $GITHUB_ENV
127+
echo "DDPT_CRUNNER_SO=${GITHUB_WORKSPACE}/third_party/install/llvm-mlir/lib/libmlir_c_runner_utils.so" >> $GITHUB_ENV
125128
- name: Test DDPT (pytest)
126129
run: |
127130
. $GITHUB_WORKSPACE/third_party/install/miniconda/etc/profile.d/conda.sh
128131
. $GITHUB_WORKSPACE/third_party/install/miniconda/bin/activate ddpt
129-
DDPT_ROOT=`pip show -f ddptensor | grep Location | awk '{print $2}'`
130-
export DDPT_IDTR_SO=${DDPT_ROOT}/ddptensor/libidtr.so
131-
export DDPT_CRUNNER_SO="$GITHUB_WORKSPACE"/third_party/install/llvm-mlir/lib/libmlir_c_runner_utils.so
132-
pytest test
133-
DDPT_FORCE_DIST=1 pytest test
132+
cd test
133+
pytest .
134+
DDPT_FORCE_DIST=1 pytest .
135+
cd -
136+
- name: Run examples
137+
run: |
138+
. $GITHUB_WORKSPACE/third_party/install/miniconda/etc/profile.d/conda.sh
139+
. $GITHUB_WORKSPACE/third_party/install/miniconda/bin/activate ddpt
140+
cd examples
141+
python -u ./stencil-2d.py 5 1024 star 4
142+
DDPT_FORCE_DIST=1 python -u ./stencil-2d.py 5 1024 star 4
143+
python -u ./wave_equation.py -ct
144+
DDPT_FORCE_DIST=1 python -u ./wave_equation.py -ct
145+
cd -
134146
- name: Cleanup
135147
run: |
136148
pip list
137149
pip uninstall -y ddptensor
138-
- run: |
139-
echo "This job's status is ${{ job.status }}."

imex_version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
399d083586cac8b2cb71f7a8da514ac2d816aac4
1+
865cea0c1af5fe7ac1458907637c28f69afd7146

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def build_cmake(self, ext):
3333
"-DCMAKE_BUILD_TYPE=" + config,
3434
"-DCMAKE_VERBOSE_MAKEFILE=ON",
3535
"-G=Ninja",
36-
"-DLLVM_ENABLE_LLD=ON"
36+
"-DLLVM_ENABLE_LLD=ON",
3737
]
3838

3939
# example of build args
@@ -56,7 +56,7 @@ def build_cmake(self, ext):
5656
name="ddptensor",
5757
version="0.1",
5858
description="Distributed Tensor and more",
59-
packages=["ddptensor"], # , "ddptensor.numpy", "ddptensor.torch"],
59+
packages=["ddptensor", "ddptensor.numpy"], # "ddptensor.torch"],
6060
ext_modules=[CMakeExtension("ddptensor/_ddptensor")],
6161
cmdclass=dict(
6262
# Enable the CMakeExtension entries defined above

src/DDPTensorImpl.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ DDPTensorImpl::DDPTensorImpl(const int64_t *shape, uint64_t N, rank_type owner)
5858

5959
DDPTensorImpl::~DDPTensorImpl() {
6060
if (!_base) {
61-
delete[] reinterpret_cast<char *>(_allocated);
61+
free(_allocated); // delete[] reinterpret_cast<char *>(_allocated);
6262
}
63-
delete[] _gs_allocated;
64-
delete[] _lo_allocated;
63+
free(_gs_allocated);
64+
free(_lo_allocated);
6565
delete[] _sizes;
6666
delete[] _strides;
6767
}
@@ -72,7 +72,8 @@ DDPTensorImpl::ptr_type DDPTensorImpl::clone(bool copy) {
7272
auto sz = size();
7373
auto esz = sizeof_dtype(dtype());
7474
auto bsz = sz * esz;
75-
auto allocated = new (std::align_val_t(esz)) char[bsz];
75+
auto allocated =
76+
aligned_alloc(esz, bsz); // new (std::align_val_t(esz)) char[bsz];
7677
auto aligned = allocated;
7778
if (copy)
7879
memcpy(aligned, _aligned, bsz);
@@ -82,7 +83,8 @@ DDPTensorImpl::ptr_type DDPTensorImpl::clone(bool copy) {
8283
// auto gs_aligned = gs_allocated;
8384
auto gs_allocated = _gs_allocated;
8485
auto gs_aligned = _gs_aligned;
85-
auto lo_allocated = new uint64_t[nd];
86+
auto lo_allocated =
87+
(uint64_t *)aligned_alloc(sizeof(uint64_t), nd * sizeof(uint64_t));
8688
auto lo_aligned = lo_allocated;
8789
memcpy(lo_aligned, _lo_aligned, nd * sizeof(*lo_aligned));
8890

@@ -94,7 +96,9 @@ DDPTensorImpl::ptr_type DDPTensorImpl::clone(bool copy) {
9496

9597
void DDPTensorImpl::alloc(bool all) {
9698
auto esz = sizeof_dtype(_dtype);
97-
_allocated = new (std::align_val_t(esz)) char[esz * local_size()];
99+
_allocated =
100+
aligned_alloc(esz, esz * local_size()); // new (std::align_val_t(esz))
101+
// char[esz * local_size()];
98102
_aligned = _allocated;
99103
_offset = 0;
100104
if (all) {

test/test_temparray.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import ddptensor as dt
2+
import pytest
3+
4+
5+
class TestTemporaries:
6+
def test_temp_inline(self):
7+
dtyp = dt.float64
8+
a = dt.ones((6, 6), dtype=dtyp)
9+
b = dt.ones((6, 6), dtype=dtyp)
10+
11+
dt.sync()
12+
c = a[0:5, 0:5]
13+
b[0:5, 0:5] = b[0:5, 0:5] + c
14+
del c
15+
dt.sync()
16+
17+
c = a[0:5, 0:5]
18+
b[0:5, 0:5] = b[0:5, 0:5] + c
19+
del c
20+
dt.sync()
21+
22+
r1 = dt.sum(b, [0, 1])
23+
v = 5 * 5 * 3 + 6 + 5
24+
assert float(r1) == v
25+
26+
def test_temp_func(self):
27+
def func(a):
28+
return a[0:5, 0:5]
29+
30+
def update(a, b):
31+
c = func(a)
32+
b[0:5, 0:5] = b[0:5, 0:5] + c
33+
34+
dtyp = dt.float64
35+
a = dt.ones((6, 6), dtype=dtyp)
36+
b = dt.ones((6, 6), dtype=dtyp)
37+
38+
dt.sync()
39+
update(a, b)
40+
dt.sync()
41+
update(a, b)
42+
dt.sync()
43+
44+
r1 = dt.sum(b, [0, 1])
45+
v = 5 * 5 * 3 + 6 + 5
46+
assert float(r1) == v

test/utils.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ def runAndCompare(func, do_gather=True):
77
a = ddptensor.spmd.gather(aa) if do_gather else aa
88
b = func(numpy)
99
if isinstance(b, numpy.ndarray):
10-
print(aa)
11-
print(a)
12-
print(b)
1310
return a.shape == b.shape and numpy.allclose(a, b, rtol=1e-8, atol=1e-8)
1411
return float(a) == float(b)
1512

0 commit comments

Comments
 (0)