Skip to content

Commit

Permalink
Make queue wait() explicit, rather than every kernel launch.
Browse files Browse the repository at this point in the history
  • Loading branch information
highperformancecoder committed Dec 11, 2024
1 parent 7167d78 commit 9840057
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
8 changes: 7 additions & 1 deletion include/ecolab.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ namespace ecolab
}
});
});
syclQ().wait();
#else
auto sz=this->size();
#ifdef _OPENMP
Expand All @@ -257,6 +256,13 @@ namespace ecolab
cell.m_idx=idx;
f(cell);
}
#endif
}

/// synchronise GPU threads
void syncThreads() {
#ifdef SYCL_LANGUAGE_VERSION
syclQ().wait();
#endif
}
};
Expand Down
3 changes: 2 additions & 1 deletion models/ecolab_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void SpatialModel::mutate()
DeviceType<array<unsigned,graphcode::Allocator<unsigned>>> cell_ids;
#ifdef SYCL_LANGUAGE_VERSION
cell_ids->allocator(graphcode::Allocator<unsigned>(syclQ(),sycl::usm::alloc::shared));
syclQ().wait();
syncThreads();
#endif

// TODO - this is a kind of scan - can it be done on device?
Expand Down Expand Up @@ -618,4 +618,5 @@ void SpatialModel::makeConsistent()
}
});
ModelData::makeConsistent(nsp);
syncThreads();
}
12 changes: 7 additions & 5 deletions models/spatial_ecolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def randomList(num, min, max):

ecolab.species(range(nsp))

numX=32
numY=32
numX=64
numY=64
ecolab.setGrid(numX,numY)
ecolab.partitionObjects()

Expand All @@ -54,15 +54,17 @@ def randomList(num, min, max):

def stepImpl():
ecolab.generate(100)
ecolab.mutate()
# ecolab.migrate()
# ecolab.condense()
# ecolab.mutate()
# ecolab.migrate()
# ecolab.condense()
ecolab.syncThreads()
ecolab.gather()

from timeit import timeit
print(timeit('stepImpl()', globals=globals(), number=10))

def step():
stepImpl()
if myid()==0:
nsp=len(ecolab.species)
statusBar.configure(text=f't={ecolab.tstep()} nsp:{nsp}')
Expand Down

0 comments on commit 9840057

Please sign in to comment.