-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. | ||
# See file LICENSE for terms. | ||
|
||
import atexit | ||
|
||
from kvikio._lib import cufile_driver # type: ignore | ||
|
||
# TODO: Wrap nicely, maybe as a dataclass? | ||
DriverProperties = cufile_driver.DriverProperties | ||
|
||
|
||
def driver_open() -> None: | ||
"""Open the cuFile driver | ||
cuFile accept multiple calls to `driver_open()`, only the first call | ||
opens the driver, but every call must have a matching call to | ||
`driver_close()`. | ||
Normally, it is not required to open and close the cuFile driver since | ||
it is done automatically. | ||
Raises | ||
------ | ||
RuntimeError | ||
If cuFile isn't available. | ||
""" | ||
return cufile_driver.driver_open() | ||
|
||
|
||
def driver_close() -> None: | ||
"""Close the cuFile driver | ||
cuFile accept multiple calls to `driver_open()`, only the first call | ||
opens the driver, but every call must have a matching call to | ||
`driver_close()`. | ||
Raises | ||
------ | ||
RuntimeError | ||
If cuFile isn't available. | ||
""" | ||
return cufile_driver.driver_close() | ||
|
||
|
||
def initialize() -> None: | ||
"""Open the cuFile driver and close it again at module exit | ||
Normally, it is not required to open and close the cuFile driver since | ||
it is done automatically. | ||
Raises | ||
------ | ||
RuntimeError | ||
If cuFile isn't available. | ||
""" | ||
driver_open() | ||
atexit.register(driver_close) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. | ||
# See file LICENSE for terms. | ||
|
||
import pytest | ||
|
||
import kvikio.cufile_driver | ||
import kvikio.defaults | ||
|
||
|
||
@pytest.mark.skipif( | ||
kvikio.defaults.compat_mode(), | ||
reason="cannot open the cuFile driver when already running in compatibility mode", | ||
) | ||
def test_open_and_close(): | ||
kvikio.cufile_driver.driver_open() | ||
kvikio.cufile_driver.driver_close() |