Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-static bounce buffer option #454

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
buffer.py
  • Loading branch information
madsbk committed Sep 2, 2024
commit c82c1d571e26e05baeb326679f2d0da4cc8af56d
11 changes: 1 addition & 10 deletions python/kvikio/kvikio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
# Copyright (c) 2021-2024, NVIDIA CORPORATION. All rights reserved.
# See file LICENSE for terms.

from kvikio._lib import buffer, driver_properties # type: ignore
from kvikio._lib import driver_properties # type: ignore
from kvikio._version import __git_commit__, __version__
from kvikio.cufile import CuFile


def memory_register(buf) -> None:
return buffer.memory_register(buf)


def memory_deregister(buf) -> None:
buffer.memory_deregister(buf)


# TODO: Wrap nicely, maybe as a dataclass?
DriverProperties = driver_properties.DriverProperties

Expand Down
17 changes: 9 additions & 8 deletions python/kvikio/kvikio/benchmarks/single_node_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from dask.utils import format_bytes, parse_bytes

import kvikio
import kvikio.buffer
import kvikio.defaults
from kvikio.benchmarks.utils import parse_directory, pprint_sys_info

Expand All @@ -38,7 +39,7 @@ def run_cufile(args):
file_path = args.dir / "kvikio-single-file"
data = create_data(args.nbytes)
if args.pre_register_buffer:
kvikio.memory_register(data)
kvikio.buffer.memory_register(data)

# Write
f = kvikio.CuFile(file_path, flags="w")
Expand All @@ -57,7 +58,7 @@ def run_cufile(args):
assert res == args.nbytes, f"IO mismatch, expected {args.nbytes} got {res}"

if args.pre_register_buffer:
kvikio.memory_deregister(data)
kvikio.buffer.memory_deregister(data)

return read_time, write_time

Expand All @@ -73,7 +74,7 @@ def run_cufile_multiple_files_multiple_arrays(args):
arrays = [create_data(chunksize) for _ in range(args.nthreads)]
if args.pre_register_buffer:
for array in arrays:
kvikio.memory_register(array)
kvikio.buffer.memory_register(array)

# Write
files = [kvikio.CuFile(file_path % i, flags="w") for i in range(args.nthreads)]
Expand All @@ -95,7 +96,7 @@ def run_cufile_multiple_files_multiple_arrays(args):

if args.pre_register_buffer:
for array in arrays:
kvikio.memory_deregister(array)
kvikio.buffer.memory_deregister(array)

return read_time, write_time

Expand All @@ -108,7 +109,7 @@ def run_cufile_multiple_files(args):
file_path = str(args.dir / "cufile-p-%03d")
data = create_data(args.nbytes)
if args.pre_register_buffer:
kvikio.memory_register(data)
kvikio.buffer.memory_register(data)

# Write
files = [kvikio.CuFile(file_path % i, flags="w") for i in range(args.nthreads)]
Expand All @@ -133,7 +134,7 @@ def run_cufile_multiple_files(args):
assert res == args.nbytes, f"IO mismatch, expected {args.nbytes} got {res}"

if args.pre_register_buffer:
kvikio.memory_deregister(data)
kvikio.buffer.memory_deregister(data)

return read_time, write_time

Expand All @@ -149,7 +150,7 @@ def run_cufile_multiple_arrays(args):
arrays = [create_data(chunksize) for _ in range(args.nthreads)]
if args.pre_register_buffer:
for array in arrays:
kvikio.memory_register(array)
kvikio.buffer.memory_register(array)

# Write
f = kvikio.CuFile(file_path, flags="w")
Expand All @@ -174,7 +175,7 @@ def run_cufile_multiple_arrays(args):

if args.pre_register_buffer:
for array in arrays:
kvikio.memory_deregister(array)
kvikio.buffer.memory_deregister(array)

return read_time, write_time

Expand Down
31 changes: 31 additions & 0 deletions python/kvikio/kvikio/buffer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
# See file LICENSE for terms.

from kvikio._lib import buffer # type: ignore


def memory_register(buf) -> None:
"""Register a device memory allocation to cuFile.
madsbk marked this conversation as resolved.
Show resolved Hide resolved

Warning
-------
This API is intended for usecases where the memory is used as streaming
madsbk marked this conversation as resolved.
Show resolved Hide resolved
buffer that is reused across multiple cuFile IO operations.

Parameters
----------
buf: buffer-like or array-like
Device buffer to register .
"""
return buffer.memory_register(buf)


def memory_deregister(buf) -> None:
"""Deregister an already registered device memory from cuFile.

Parameters
----------
buf: buffer-like or array-like
Device buffer to deregister .
"""
buffer.memory_deregister(buf)