Metadata-Version: 2.1
Name: caggpu
Version: 0.0.2
Summary: A GPU utility package for Coargus services.
Author-email: "minkyu.choi" <minkyu.choi07@gmail.com>
License: MIT License
        
        Copyright (c) 2024 Coargus
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: homepage, https://github.com/Coargus/utility-pkg-gpu/
Project-URL: documentation, https://github.com/Coargus/utility-pkg-gpu/docs
Project-URL: repository, https://github.com/Coargus/utility-pkg-gpu/
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pynvml
Provides-Extra: dev
Requires-Dist: black; extra == "dev"
Requires-Dist: flake8; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Provides-Extra: test
Requires-Dist: pytest>=6.0; extra == "test"
Requires-Dist: pytest-cov; extra == "test"

# GPU Utility Package

This Python module provides tools for managing GPUs in a machine learning or high-performance computing environment. It allows users to identify free GPUs with a specified amount of available memory and optionally set the `CUDA_VISIBLE_DEVICES` or other required gpu environment variable to use those GPUs.

## Features

- **Check for Free GPUs**: Determine which GPUs on the system have a minimum specified amount of free memory.
- **Set CUDA Environment**: Automatically set the `CUDA_VISIBLE_DEVICES` environment variable to use GPUs that meet the memory requirements.

## Requirements

- Python 3.8 or higher
- `pynvml`: Python bindings for the NVIDIA Management Library
- `subprocess` module (standard in Python)

## Usage

**Getting Free GPUs**
You can retrieve a list of GPUs that have at least a specified amount of free memory. You can specify whether to use the NVIDIA System Management Interface (nvidia-smi) or the NVML library.

```
from gpu_modules import get_free_gpus

# Get free GPUs with at least 10 GB of free memory using NVML
free_gpus = get_free_gpus(10240)
print("Free GPUs:", free_gpus)

# Alternatively, use nvidia-smi to check for free GPUs
free_gpus_smi = get_free_gpus(10240, use_nvidia_smi=True)
print("Free GPUs using nvidia-smi:", free_gpus_smi)

```

## Setting CUDA Visible Devices
To set the CUDA_VISIBLE_DEVICES environment variable automatically based on free memory:
```
from gpu_modules import set_cuda_visible_devices

# Set CUDA_VISIBLE_DEVICES for GPUs with at least 10 GB free memory
if set_cuda_visible_devices(10240):
    print("CUDA_VISIBLE_DEVICES set successfully.")
else:
    print("No free GPUs available.")

```

## Contributing
Contributions to this project are welcome. Please submit a pull request or open an issue to discuss proposed changes or report bugs.
