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

Commit 9abdeab

Browse files
committed
adding GC
1 parent ccef45d commit 9abdeab

37 files changed

+264
-184
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def build_cmake(self, ext):
2929
extdir.parent.mkdir(parents=True, exist_ok=True)
3030

3131
# example of cmake args
32-
config = 'Debug' # if self.debug else 'Release' # 'RelWithDebInfo' #'Release'
32+
config = 'Debug' if self.debug else 'Release' # 'RelWithDebInfo' #'Release'
3333
cmake_args = [
3434
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + str(extdir.parent.absolute()),
3535
'-DCMAKE_BUILD_TYPE=' + config

src/Creator.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ struct DeferredFromShape : public Deferred
8989
}
9090
};
9191

92-
tensor_i::future_type Creator::create_from_shape(CreatorId op, const shape_type & shape, DTypeId dtype)
92+
ddptensor * Creator::create_from_shape(CreatorId op, const shape_type & shape, DTypeId dtype)
9393
{
94-
return defer<DeferredFromShape>(op, shape, dtype);
94+
return new ddptensor(defer<DeferredFromShape>(op, shape, dtype));
9595
}
9696

9797
struct DeferredFull : public Deferred
@@ -125,10 +125,10 @@ struct DeferredFull : public Deferred
125125
}
126126
};
127127

128-
tensor_i::future_type Creator::full(const shape_type & shape, const py::object & val, DTypeId dtype)
128+
ddptensor * Creator::full(const shape_type & shape, const py::object & val, DTypeId dtype)
129129
{
130130
auto v = mk_scalar(val, dtype);
131-
return defer<DeferredFull>(shape, v, dtype);
131+
return new ddptensor(defer<DeferredFull>(shape, v, dtype));
132132
}
133133

134134
struct DeferredArange : public Deferred
@@ -161,15 +161,15 @@ struct DeferredArange : public Deferred
161161
}
162162
};
163163

164-
tensor_i::future_type Creator::arange(uint64_t start, uint64_t end, uint64_t step, DTypeId dtype)
164+
ddptensor * Creator::arange(uint64_t start, uint64_t end, uint64_t step, DTypeId dtype)
165165
{
166-
return defer<DeferredArange>(start, end, step, dtype);
166+
return new ddptensor(defer<DeferredArange>(start, end, step, dtype));
167167
}
168168

169-
tensor_i::future_type Creator::mk_future(const py::object & b)
169+
ddptensor * Creator::mk_future(const py::object & b)
170170
{
171-
if(py::isinstance<tensor_i::future_type>(b)) {
172-
return b.cast<tensor_i::future_type>();
171+
if(py::isinstance<ddptensor>(b)) {
172+
return b.cast<ddptensor*>();
173173
} else if(py::isinstance<py::float_>(b)) {
174174
return Creator::full({1}, b, FLOAT64);
175175
} else if(py::isinstance<py::int_>(b)) {

src/Deferred.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ Deferred::future_type Deferred::get_future()
1111
return {std::move(tensor_i::promise_type::get_future()), _guid};
1212
}
1313

14+
#if 0
1415
void Deferred::set_value(tensor_i::ptr_type && v)
1516
{
1617
if(_guid != Registry::NOGUID) {
1718
Registry::put(_guid, v);
1819
}
1920
tensor_i::promise_type::set_value(std::forward<tensor_i::ptr_type>(v));
2021
}
22+
#endif
2123

2224
Deferred::future_type Deferred::defer(Deferred::ptr_type && d, bool is_global)
2325
{
@@ -26,6 +28,7 @@ Deferred::future_type Deferred::defer(Deferred::ptr_type && d, bool is_global)
2628
if(d) d->_guid = Registry::get_guid();
2729
}
2830
auto f = d ? d->get_future() : Deferred::future_type();
31+
Registry::put(f);
2932
_deferred.push(std::move(d));
3033
return f;
3134
}

src/EWBinOp.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ struct DeferredEWBinOp : public Deferred
149149

150150
void run()
151151
{
152-
const auto a = std::move(Registry::get(_a));
153-
const auto b = std::move(Registry::get(_b));
152+
const auto a = std::move(Registry::get(_a).get());
153+
const auto b = std::move(Registry::get(_b).get());
154154
set_value(std::move(TypeDispatch<x::EWBinOp>(a, b, _op)));
155155
}
156156

@@ -168,13 +168,13 @@ struct DeferredEWBinOp : public Deferred
168168
}
169169
};
170170

171-
tensor_i::future_type EWBinOp::op(EWBinOpId op, const tensor_i::future_type & a, const py::object & b)
171+
ddptensor * EWBinOp::op(EWBinOpId op, const ddptensor & a, const py::object & b)
172172
{
173173
auto bb = Creator::mk_future(b);
174174
if(op == __MATMUL__) {
175-
return LinAlgOp::vecdot(a, bb, 0);
175+
return LinAlgOp::vecdot(a, *bb, 0);
176176
}
177-
return defer<DeferredEWBinOp>(op, a, bb);
177+
return new ddptensor(defer<DeferredEWBinOp>(op, a.get(), bb->get()));
178178
}
179179

180180
FACTORY_INIT(DeferredEWBinOp, F_EWBINOP);

src/EWUnyOp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ struct DeferredEWUnyOp : public Deferred
121121

122122
void run()
123123
{
124-
const auto a = std::move(Registry::get(_a));
124+
const auto a = std::move(Registry::get(_a).get());
125125
set_value(std::move(TypeDispatch<x::EWUnyOp>(a, _op)));
126126
}
127127

@@ -138,9 +138,9 @@ struct DeferredEWUnyOp : public Deferred
138138
}
139139
};
140140

141-
tensor_i::future_type EWUnyOp::op(EWUnyOpId op, const tensor_i::future_type & a)
141+
ddptensor * EWUnyOp::op(EWUnyOpId op, const ddptensor & a)
142142
{
143-
return defer<DeferredEWUnyOp>(op, a);
143+
return new ddptensor(defer<DeferredEWUnyOp>(op, a.get()));
144144
}
145145

146146
FACTORY_INIT(DeferredEWUnyOp, F_EWUNYOP);

src/IEWBinOp.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ struct DeferredIEWBinOp : public Deferred
8282
IEWBinOpId _op;
8383

8484
DeferredIEWBinOp() = default;
85-
DeferredIEWBinOp(IEWBinOpId op, tensor_i::future_type & a, const tensor_i::future_type & b)
85+
DeferredIEWBinOp(IEWBinOpId op, const tensor_i::future_type & a, const tensor_i::future_type & b)
8686
: _a(a.id()), _b(b.id()), _op(op)
8787
{}
8888

8989
void run()
9090
{
91-
const auto a = std::move(Registry::get(_a));
92-
const auto b = std::move(Registry::get(_b));
91+
const auto a = std::move(Registry::get(_a).get());
92+
const auto b = std::move(Registry::get(_b).get());
9393
set_value(std::move(TypeDispatch<x::IEWBinOp>(a, b, _op)));
9494
}
9595

@@ -107,9 +107,10 @@ struct DeferredIEWBinOp : public Deferred
107107
}
108108
};
109109

110-
tensor_i::future_type IEWBinOp::op(IEWBinOpId op, tensor_i::future_type & a, const py::object & b)
110+
ddptensor * IEWBinOp::op(IEWBinOpId op, ddptensor & a, const py::object & b)
111111
{
112-
return defer<DeferredIEWBinOp>(op, a, Creator::mk_future(b));
112+
auto bb = Creator::mk_future(b);
113+
return new ddptensor(defer<DeferredIEWBinOp>(op, a.get(), bb->get()));
113114
}
114115

115116
FACTORY_INIT(DeferredIEWBinOp, F_IEWBINOP);

src/LinAlgOp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ struct DeferredLinAlgOp : public Deferred
123123

124124
void run()
125125
{
126-
const auto a = std::move(Registry::get(_a));
127-
const auto b = std::move(Registry::get(_b));
126+
const auto a = std::move(Registry::get(_a).get());
127+
const auto b = std::move(Registry::get(_b).get());
128128
set_value(std::move(TypeDispatch<x::LinAlgOp>(a, b, _axis)));
129129
}
130130

@@ -142,9 +142,9 @@ struct DeferredLinAlgOp : public Deferred
142142
}
143143
};
144144

145-
tensor_i::future_type LinAlgOp::vecdot(const tensor_i::future_type & a, const tensor_i::future_type & b, int axis)
145+
ddptensor * LinAlgOp::vecdot(const ddptensor & a, const ddptensor & b, int axis)
146146
{
147-
return defer<DeferredLinAlgOp>(a, b, axis);
147+
return new ddptensor(defer<DeferredLinAlgOp>(a.get(), b.get(), axis));
148148
}
149149

150150
FACTORY_INIT(DeferredLinAlgOp, F_LINALGOP);

src/MPIMediator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void MPIMediator::pull(rank_type from, id_type guid, const NDSlice & slice, void
6464
ser.adapter().flush();
6565
int cnt = static_cast<int>(ser.adapter().writtenBytesCount());
6666

67-
auto sz = slice.size() * Registry::get(id)->item_size();
67+
auto sz = slice.size() * Registry::get(id).get()->item_size();
6868
MPI_Irecv(rbuff, sz, MPI_CHAR, from, PUSH_TAG, comm, &request[1]);
6969
MPI_Isend(buff.data(), cnt, MPI_CHAR, from, REQ_TAG, comm, &request[0]);
7070
auto error_code = MPI_Waitall(2, &request[0], &status[0]);
@@ -173,7 +173,7 @@ void MPIMediator::listen()
173173
MPI_Irecv(buff.data(), buff.size(), MPI_CHAR, MPI_ANY_SOURCE, REQ_TAG, comm, &request_in);
174174

175175
// Now find the array in question and send back its bufferized slice
176-
tensor_i::ptr_type ptr = Registry::get(id);
176+
tensor_i::ptr_type ptr = Registry::get(id).get();
177177
// Wait for previous answer to complete so that we can re-use the buffer
178178
MPI_Wait(&request_out, MPI_STATUS_IGNORE);
179179
ptr->bufferize(slice, rbuff);

src/ManipOp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct DeferredManipOp : public Deferred
3636

3737
void run()
3838
{
39-
const auto a = std::move(Registry::get(_a));
39+
const auto a = std::move(Registry::get(_a).get());
4040
set_value(std::move(TypeDispatch<x::ManipOp>(a, _shape)));
4141
}
4242

@@ -53,9 +53,9 @@ struct DeferredManipOp : public Deferred
5353
}
5454
};
5555

56-
tensor_i::future_type ManipOp::reshape(const tensor_i::future_type & a, const shape_type & shape)
56+
ddptensor * ManipOp::reshape(const ddptensor & a, const shape_type & shape)
5757
{
58-
return defer<DeferredManipOp>(a, shape);
58+
return new ddptensor(defer<DeferredManipOp>(a.get(), shape));
5959
}
6060

6161
FACTORY_INIT(DeferredManipOp, F_MANIPOP);

src/Random.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ struct DeferredRandomOp : public Deferred
6262
};
6363

6464

65-
Random::future_type Random::rand(DTypeId dtype, const shape_type & shape, const py::object & lower, const py::object & upper)
65+
ddptensor * Random::rand(DTypeId dtype, const shape_type & shape, const py::object & lower, const py::object & upper)
6666
{
67-
return defer<DeferredRandomOp>(shape, x::to_native<double>(lower), x::to_native<double>(upper), dtype);
67+
return new ddptensor(defer<DeferredRandomOp>(shape, x::to_native<double>(lower), x::to_native<double>(upper), dtype));
6868
}
6969

7070
void Random::seed(uint64_t s)

0 commit comments

Comments
 (0)