Skip to content

Commit

Permalink
Do not create CPU copy of grad array when calling array.numpy()
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-heiden authored and c0d1f1ed committed Jan 11, 2024
1 parent 7aaa811 commit 20db9c6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions warp/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1966,7 +1966,7 @@ def numpy(self):
if self.ptr:
# use the CUDA default stream for synchronous behaviour with other streams
with warp.ScopedStream(self.device.null_stream):
a = self.to("cpu")
a = self.to("cpu", requires_grad=False)
# convert through __array_interface__
# Note: this handles arrays of structs using `descr`, so the result will be a structured NumPy array
return np.array(a, copy=False)
Expand Down Expand Up @@ -2031,13 +2031,13 @@ def list(self):
# scalar
return list(a.flatten())

def to(self, device):
def to(self, device, requires_grad=None):
"""Returns a Warp array with this array's data moved to the specified device, no-op if already on device."""
device = warp.get_device(device)
if self.device == device:
return self
else:
return warp.clone(self, device=device)
return warp.clone(self, device=device, requires_grad=requires_grad)

def flatten(self):
"""Returns a zero-copy view of the array collapsed to 1-D. Only supported for contiguous arrays."""
Expand Down

0 comments on commit 20db9c6

Please sign in to comment.