Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
Added wrap inner and vec_context in cuda
Browse files Browse the repository at this point in the history
  • Loading branch information
Clara committed May 5, 2020
1 parent 04612c6 commit 9f1f57b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pyop2/gpu/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,23 @@ def data(self):
@property
def data_ro(self):
with self.vec_ro as v:
v.restoreCUDAHandle(self.device_handle)
v.restoreCUDAHandle(self.device_handle, mode='r')
return v.array

@contextmanager
def vec_context(self, access):
r"""A context manager for a :class:`PETSc.Vec` from a :class:`Dat`.
:param access: Access descriptor: READ, WRITE, or RW."""
# PETSc Vecs have a state counter and cache norm computations
# to return immediately if the state counter is unchanged.
# Since we've updated the data behind their back, we need to
# change that state counter.
self._vec.stateIncrease()
yield self._vec
if access is not base.READ:
self.halo_valid = False
self._vec.restoreCUDAHandle(self._vec.getCUDAHandle())

This comment has been minimized.

Copy link
@kaushikcfd

kaushikcfd May 6, 2020

Contributor

@Clara322: This logic is already handled by petsc_base.Dat.


class Global(petsc_Global):

Expand Down Expand Up @@ -373,6 +387,7 @@ def compile(self):

compiler = "nvcc"
extension = "cu"
#print("{0}".format(self._wrapper_name))
self._fun = compilation.load(self,
extension,
self._wrapper_name,
Expand Down Expand Up @@ -639,7 +654,7 @@ def insn_needs_atomic(insn):
"wrap_form_cell_integral_otherwise",
"wrap_loopy_kernel_prolong",
"wrap_loopy_kernel_restrict",
"wrap_loopy_kernel_inject", "wrap_copy"
"wrap_loopy_kernel_inject", "wrap_copy", "wrap_inner"
]:
from pyop2.gpu.snpt import snpt_transform
kernel, args_to_make_global = snpt_transform(kernel,
Expand Down

0 comments on commit 9f1f57b

Please sign in to comment.