Skip to content

Commit

Permalink
polish dataset use jittor with cuda
Browse files Browse the repository at this point in the history
  • Loading branch information
cjld committed Apr 23, 2022
1 parent 5e559cf commit cc6cb28
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/jittor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# file 'LICENSE.txt', which is part of this source code package.
# ***************************************************************

__version__ = '1.3.3.5'
__version__ = '1.3.3.6'
from jittor_utils import lock
with lock.lock_scope():
ori_int = int
Expand Down
1 change: 1 addition & 0 deletions python/jittor/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ def _stop_all_workers(self):
self.gid_obj.value = 0

def _init_workers(self, index_list):
jt.migrate_all_to_cpu()
jt.clean()
jt.gc()
self.index_list = mp.Array('i', self.real_len, lock=False)
Expand Down
11 changes: 11 additions & 0 deletions python/jittor/src/var_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,16 @@ VarHolder* ternary_out_hint(VarHolder* cond, VarHolder* x, VarHolder* y) {
return new VarHolder(make_ternary(cond->var, x->var, y->var));
}

void migrate_all_to_cpu() {
sync_all(true);
#ifdef HAS_CUDA
for (auto vh : hold_vars) {
auto v = vh->var;
if (v->_outputs.size()) continue;
if (v->allocator && !v->allocator->is_cuda())
migrate_to_gpu(v, cpu_allocator);
}
#endif
}

} // jittor
3 changes: 3 additions & 0 deletions python/jittor/src/var_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,7 @@ inline vector<VarHolder*> make_vh_vector(vector<VarPtr>&& vps) {
// @pyjt(ternary_out_hint)
VarHolder* ternary_out_hint(VarHolder* cond, VarHolder* x, VarHolder* y);

// @pyjt(migrate_all_to_cpu)
void migrate_all_to_cpu();

} // jittor

0 comments on commit cc6cb28

Please sign in to comment.