Skip to content

Instantly share code, notes, and snippets.

@tianrluo
Created January 22, 2020 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tianrluo/69f5613d270c7286cdeb51e33ed16dda to your computer and use it in GitHub Desktop.
Save tianrluo/69f5613d270c7286cdeb51e33ed16dda to your computer and use it in GitHub Desktop.
# inspired by gist.github.com/f0k/63a664160d016a491b2cbea15913d549
from setuptools import setup, find_packages
import ctypes
def cuda_is_available():
libnames = ('libcuda.so', 'libcuda.dylib', 'cuda.dll')
for name in libnames:
try:
ctypes.CDLL(name)
except OSError:
continue
else:
return True
else:
return False
return False
"""
it seems github dependency checker only cares about the initial
definition of the `REQUIRED_PACKAGES` variable. Hence appending
`cupy` at the initialization, pop it when `cuda` is missing.
"""
REQUIRED_PACKAGES = ['torch>=1.3', 'numpy', 'cupy>=7.0.0']
if not cuda_is_available():
REQUIRED_PACKAGES.remove('cupy>=7.0.0')
@speedcell4
Copy link

isn't torch.cuda.is_available() more convenient?

@tianrluo
Copy link
Author

@speedcell4

isn't torch.cuda.is_available() more convenient?

At CI install time, torch is often not available yet.

@speedcell4
Copy link

speedcell4 commented Jan 23, 2020

actually, you can add pip install torch before python setup.py install in your CI config file.

@tianrluo
Copy link
Author

@speedcell4
Ah... wasn't aware of that...
Then I guess the only benefit of the configs here is that ctypes comes w/ python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment