Skip to main content

Mask GPU

A simple tool to expose only specified number of GPUs with desired memory to Tensorflow (and a few more apps, read further). This tool queries GPU free memory values using nvidia-smi and assigns CUDA_VISIBLE_DEVICES environment variable based on the specified memory and number of GPUs to expose, to expose specific GPUs. Apps such as tensorflow-gpu use this information and utilize only the GPUs that are exposed. If your app does not make use of CUDA_VISIBLE_DEVICES, then this is probably not what you would need.

Dependencies

  • nvidia-smi

Installation

pip install mask-gpu

Quick Start

To show available GPUs info

mask-gpu --info
# Outputs the following
# Finding GPUs with a minimum of 1024MiB free memory...
# GPUs available: 6 -> [0, 1, 4, 5, 6, 7]

Simply run mask-gpu to expose 1 GPU (with a minimum of 1024MiB free memory)

`mask-gpu`
# Remember to wrap mask-gpu in ` symbol
# Or else mask-gpu will print the command
# and you will have to manually execute it

Specifying Options

By default mask-gpu seraches for GPUs with atleast 1024M free memory and allots 1 GPU

mask-gpu --info --min_memory 1024
# mask-gpu -i -m 1024                <--- Same as above
# Info does not execute any commands

`mask-gpu --expose 1 --min_memory 1024`
# `mask-gpu -e 3 -m 1024`            <--- Same as above
# Remember to wrap mask-gpu in ` symbol

You can specify your own options using the above as the template

Unmask all (Revert)

To unmask all GPUs, i.e, to revert to what it was before using mask-gpu

`mask-gpu --unmask-all`
# `mask-gpu -u`                      <--- Same as above
# Remember to wrap mask-gpu in ` symbol

NOTE: This command will clear CUDA_VISIBLE_DEVICES and hence it will be erased when executing the above command

Licence

The MIT License

Copyright (c) 2019 Saravanabalagi Ramachandran

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.

Metadata

Release files for mask-gpu 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for mask-gpu 0.1.0
File Interpreter ABI Platform
mask_gpu-0.1.0-py3-none-any.whl Python 3 none any Details

Release files / mask_gpu-0.1.0-py3-none-any.whl

Download URL mask_gpu-0.1.0-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6a46a7af4379579a901b774807be3c479b99103186c7b69b3cb0a71006cf3b4d
BLAKE2b-256 checksum
How to use checksums
957764e814405b2d0a52aaffbe136856065907cfd0b62e2642ce303cf57b47dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page