Skip to content

Commit

Permalink
rename _from_*_memory => from_*_memory
Browse files Browse the repository at this point in the history
  • Loading branch information
madsbk committed Apr 11, 2024
1 parent ac6831a commit 49625fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
14 changes: 7 additions & 7 deletions python/cudf/cudf/core/buffer/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class BufferOwner(Serializable):
been accessed outside of BufferOwner. In this case, we have no control
over knowing if the data is being modified by a third party.
Use `_from_device_memory` and `_from_host_memory` to create
Use `from_device_memory` and `from_host_memory` to create
a new instance from either device or host memory respectively.
Parameters
Expand Down Expand Up @@ -152,7 +152,7 @@ def __init__(
self._slices = weakref.WeakSet()

@classmethod
def _from_device_memory(cls, data: Any, exposed: bool) -> Self:
def from_device_memory(cls, data: Any, exposed: bool) -> Self:
"""Create from an object providing a `__cuda_array_interface__`.
No data is being copied.
Expand Down Expand Up @@ -187,7 +187,7 @@ def _from_device_memory(cls, data: Any, exposed: bool) -> Self:
return cls(ptr=ptr, size=size, owner=data, exposed=exposed)

@classmethod
def _from_host_memory(cls, data: Any) -> Self:
def from_host_memory(cls, data: Any) -> Self:
"""Create an owner from a buffer or array like object
Data must implement `__array_interface__`, the buffer protocol, and/or
Expand Down Expand Up @@ -215,7 +215,7 @@ def _from_host_memory(cls, data: Any) -> Self:
# Copy to device memory
buf = rmm.DeviceBuffer(ptr=ptr, size=size)
# Create from device memory
return cls._from_device_memory(buf, exposed=False)
return cls.from_device_memory(buf, exposed=False)

@property
def size(self) -> int:
Expand Down Expand Up @@ -394,7 +394,7 @@ def copy(self, deep: bool = True) -> Self:
)

# Otherwise, we create a new copy of the memory
owner = self._owner._from_device_memory(
owner = self._owner.from_device_memory(
rmm.DeviceBuffer(
ptr=self._owner.get_ptr(mode="read") + self._offset,
size=self.size,
Expand Down Expand Up @@ -458,9 +458,9 @@ def deserialize(cls, header: dict, frames: list) -> Self:

owner_type: BufferOwner = pickle.loads(header["owner-type-serialized"])
if hasattr(frame, "__cuda_array_interface__"):
owner = owner_type._from_device_memory(frame, exposed=False)
owner = owner_type.from_device_memory(frame, exposed=False)
else:
owner = owner_type._from_host_memory(frame)
owner = owner_type.from_host_memory(frame)
return cls(
owner=owner,
offset=0,
Expand Down
14 changes: 7 additions & 7 deletions python/cudf/cudf/core/buffer/spillable_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class SpillableBufferOwner(BufferOwner):
def _finalize_init(self, ptr_desc: Dict[str, Any]) -> None:
"""Finish initialization of the spillable buffer
This implements the common initialization that `_from_device_memory`
and `_from_host_memory` are missing.
This implements the common initialization that `from_device_memory`
and `from_host_memory` are missing.
Parameters
----------
Expand All @@ -120,7 +120,7 @@ def _finalize_init(self, ptr_desc: Dict[str, Any]) -> None:
self._manager.add(self)

@classmethod
def _from_device_memory(cls, data: Any, exposed: bool) -> Self:
def from_device_memory(cls, data: Any, exposed: bool) -> Self:
"""Create a spillabe buffer from device memory.
No data is being copied.
Expand All @@ -137,12 +137,12 @@ def _from_device_memory(cls, data: Any, exposed: bool) -> Self:
SpillableBufferOwner
Buffer representing the same device memory as `data`
"""
ret = super()._from_device_memory(data, exposed=exposed)
ret = super().from_device_memory(data, exposed=exposed)
ret._finalize_init(ptr_desc={"type": "gpu"})
return ret

@classmethod
def _from_host_memory(cls, data: Any) -> Self:
def from_host_memory(cls, data: Any) -> Self:
"""Create a spillabe buffer from host memory.
Data must implement `__array_interface__`, the buffer protocol, and/or
Expand Down Expand Up @@ -426,7 +426,7 @@ def serialize(self) -> Tuple[dict, list]:
ptr, size, _ = self.memory_info()
frames = [
Buffer(
owner=BufferOwner._from_device_memory(
owner=BufferOwner.from_device_memory(
cuda_array_interface_wrapper(
ptr=ptr,
size=size,
Expand All @@ -448,7 +448,7 @@ def copy(self, deep: bool = True) -> Self:
# In this case, we make the new copy point to the same spilled
# data in host memory. We can do this since spilled data is never
# modified.
owner = self._owner._from_host_memory(self.memoryview())
owner = self._owner.from_host_memory(self.memoryview())
return self.__class__(owner=owner, offset=0, size=owner.size)

with acquire_spill_lock():
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/buffer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ def as_buffer(
if not hasattr(data, "__cuda_array_interface__"):
if exposed:
raise ValueError("cannot created exposed host memory")
return buffer_class(owner=owner_class._from_host_memory(data))
return buffer_class(owner=owner_class.from_host_memory(data))

# Check if `data` is owned by a known class
owner = get_buffer_owner(data)
if owner is None: # `data` is new device memory
return buffer_class(
owner=owner_class._from_device_memory(data, exposed=exposed)
owner=owner_class.from_device_memory(data, exposed=exposed)
)

# At this point, we know that `data` is owned by a known class, which
Expand Down

0 comments on commit 49625fa

Please sign in to comment.