Skip to content

Commit

Permalink
Using enqueue_copy in place of deprecated enqueue_read_buffer
Browse files Browse the repository at this point in the history
Fixing tests for cl_common.cl
  • Loading branch information
kunal-puri committed Apr 27, 2011
1 parent 253fe87 commit 3db3e74
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
3 changes: 1 addition & 2 deletions source/pysph/base/particle_array.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1255,8 +1255,7 @@ cdef class ParticleArray:
if dtype == "long":
array = array.astype(numpy.int32)

cl.enqueue_read_buffer(self.queue, buffer, array).wait()
#cl.enqueue_copy_buffer(self.queue, buffer, array).wait()
cl.enqueue_copy(self.queue, src=buffer, dest=array).wait()

self.set( **{prop:array} )

Expand Down
30 changes: 17 additions & 13 deletions source/pysph/solver/cl_integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ def set_initial_buffers(self):
update_prop_buffer = pa.get_cl_buffer(update_prop)
initial_prop_buffer = pa.get_cl_buffer(initial_prop)

cl.enqueue_copy_buffer(queue=queue, src=update_prop_buffer,
dst=initial_prop_buffer).wait()
cl.enqueue_copy(queue=queue, src=update_prop_buffer,
dest=initial_prop_buffer,
).wait()

pa.read_from_buffer()

Expand Down Expand Up @@ -106,8 +107,8 @@ def reset_current_buffers(self, calcs):

# reset the current property to the initial array

cl.enqueue_copy_buffer(queue=queue,src=initial_prop_buffer,
dst=update_prop_buffer)
cl.enqueue_copy(queue=queue,src=initial_prop_buffer,
dest=update_prop_buffer)


def eval(self, calcs):
Expand Down Expand Up @@ -146,7 +147,7 @@ def eval(self, calcs):
update_prop_buffer = pa.get_cl_buffer(update_prop)

cl.enqueue_copy_buffer(queue, src=step_prop_buffer,
dst=update_prop_buffer).wait()
dest=update_prop_buffer).wait()

# ensure that all processes have reached this point

Expand All @@ -169,8 +170,9 @@ def eval(self, calcs):

k_prop_buffer = pa.get_cl_buffer(k_prop)

cl.enqueue_copy_buffer(queue, src=step_prop_buffer,
dst=k_prop_buffer).wait()
cl.enqueue_copy(queue, src=step_prop_buffer,
dest=k_prop_buffer,
).wait()

pass

Expand Down Expand Up @@ -212,8 +214,8 @@ def step(self, calcs, dt):
current_buffer, step_buffer,
tmp_buffer, cl_dt)

cl.enqueue_copy_buffer(queue, src=tmp_buffer,
dst=current_buffer)
cl.enqueue_copy(queue, src=tmp_buffer,
dest=current_buffer)

pass
pass
Expand Down Expand Up @@ -260,11 +262,13 @@ def final_step(self, calc, dt):
initial_buffer, k1_buffer,
tmp_buffer, cl_dt).wait()

cl.enqueue_copy_buffer(queue, src=tmp_buffer,
dst=initial_buffer).wait()
cl.enqueue_copy(queue, src=tmp_buffer,
dest=initial_buffer,
).wait()

cl.enqueue_copy_buffer(queue, src=tmp_buffer,
dst=update_buffer).wait()
cl.enqueue_copy(queue, src=tmp_buffer,
dest=update_buffer,
).wait()

def integrate(self, dt):

Expand Down
9 changes: 5 additions & 4 deletions source/pysph/solver/tests/test_cl_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@
args = (ybuf, zbuf)

pysph_root = solver.get_pysph_root()
src = open(path.join(pysph_root, 'solver/cl_common.cl')).read()
src = solver.cl_read(path.join(pysph_root, 'solver/cl_common.cl'),
precision='single')

prog = cl.Program(ctx, src).build(options=solver.get_cl_include())

# launch the OpenCL kernel
prog.set_tmp_to_zero(q, (16, 16, 16), (1,1,1), xbuf, *args)

# read the buffer contents back to the arrays
cl.enqueue_read_buffer(q, xbuf, x).wait()
cl.enqueue_read_buffer(q, ybuf, y).wait()
cl.enqueue_read_buffer(q, zbuf, z).wait()
cl.enqueue_copy(q, src=xbuf, dest=x).wait()
cl.enqueue_copy(q, src=ybuf, dest=y).wait()
cl.enqueue_copy(q, src=zbuf, dest=z).wait()

for i in range(np):
assert x[i] == 0.0
Expand Down

0 comments on commit 3db3e74

Please sign in to comment.