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

use HAS_GPU to determine of cuda is available #364

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 3 additions & 13 deletions merlin/core/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

from merlin.core.has_gpu import HAS_GPU # noqa pylint: disable=unused-import

if not cuda.is_available():
cuda = None
cuda = None if not HAS_GPU else cuda

try:
import psutil
Expand Down Expand Up @@ -98,17 +97,8 @@ def device_mem_size(kind="total", cpu=False):

if kind not in ["free", "total"]:
raise ValueError(f"{kind} not a supported option for device_mem_size.")
try:
if kind == "free":
return int(cuda.current_context().get_memory_info()[0])
else:
return int(cuda.current_context().get_memory_info()[1])
except NotImplementedError:
if kind == "free":
# Not using NVML "free" memory, because it will not include RMM-managed memory
warnings.warn("get_memory_info is not supported. Using total device memory from NVML.")
size = pynvml_mem_size(kind="total", index=0)
return size

return pynvml_mem_size(kind=kind)


try:
Expand Down
6 changes: 5 additions & 1 deletion merlin/io/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,11 @@ def _add_data_slice(self, df):
if self.shuffle:
df = shuffle_df(df)
int_slice_size = df.shape[0] // self.num_out_files
slice_size = int_slice_size if df.shape[0] % int_slice_size == 0 else int_slice_size + 1
slice_size = (
int_slice_size
if int_slice_size > 0 and df.shape[0] % int_slice_size == 0
else int_slice_size + 1
)
for x in range(self.num_out_files):
start = x * slice_size
end = start + slice_size
Expand Down
Loading