Skip to content

Commit

Permalink
Add stream sync barriers
Browse files Browse the repository at this point in the history
When blocks blocks write to a ring across the CPU/GPU boundary
this copy is [I think] asynchronous, and needs to be
synchronized before marking the destination buffer as ready
for consumption by downstream consumers.

See ledatelescope/bifrost#138
  • Loading branch information
JackH committed Jun 23, 2020
1 parent 5a460d2 commit 1402809
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions test-scripts/blocks/copy_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from bifrost.linalg import LinAlg
from bifrost import map as BFMap
from bifrost.ndarray import copy_array
from bifrost.device import stream_synchronize

import time
import json
Expand Down Expand Up @@ -54,3 +55,6 @@ def main(self):
#self.log.debug("Copying output")
#odata = ospan.data_view('ci4')
copy_array(ospan.data, ispan.data)
# The copy is asynchronous, so we must wait for it to finish
# before committing this span
stream_synchronize()
9 changes: 6 additions & 3 deletions test-scripts/blocks/corr_acc_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from bifrost.ring import WriteSpan
from bifrost.linalg import LinAlg
from bifrost import map as BFMap
from bifrost.ndarray import copy_array
from bifrost.device import stream_synchronize

import time
import json
Expand Down Expand Up @@ -73,9 +75,10 @@ def main(self):
print("Skipping output because oseq isn't open")
else:
# copy to CPU
odata = ospan.data_view('i32')
odata = self.accdata
print(odata[0:10])
odata = ospan.data_view('i32').reshape(self.accdata.shape)
copy_array(odata, self.accdata)
# Wait for copy to complete before committing span
stream_synchronize()
ospan.close()
oseq.end()
# If upstream process stops producing, close things gracefully
Expand Down
3 changes: 3 additions & 0 deletions test-scripts/blocks/corr_subsel_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from bifrost.linalg import LinAlg
from bifrost import map as BFMap
from bifrost.ndarray import copy_array
from bifrost.device import stream_synchronize

import time
import json
Expand Down Expand Up @@ -64,3 +65,5 @@ def main(self):
raise RuntimeError
odata = ospan.data_view(dtype='i64').reshape([self.nchans, self.nvis_out])
copy_array(odata, self.obuf_gpu)
# Wait for copy to complete before committing span
stream_synchronize()

0 comments on commit 1402809

Please sign in to comment.