Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
bitsandbytes
Commits
38092364
Commit
38092364
authored
Aug 02, 2022
by
Titus von Koeller
Browse files
move cuda_setup code into subpackage
parent
e120c4a5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
3 deletions
+69
-3
bitsandbytes/__init__.py
bitsandbytes/__init__.py
+1
-0
bitsandbytes/cextension.py
bitsandbytes/cextension.py
+1
-1
bitsandbytes/cuda_setup/__init__.py
bitsandbytes/cuda_setup/__init__.py
+0
-0
bitsandbytes/cuda_setup/compute_capability.py
bitsandbytes/cuda_setup/compute_capability.py
+65
-0
bitsandbytes/cuda_setup/main.py
bitsandbytes/cuda_setup/main.py
+2
-2
No files found.
bitsandbytes/__init__.py
View file @
38092364
...
...
@@ -12,6 +12,7 @@ from .autograd._functions import (
)
from
.cextension
import
COMPILED_WITH_CUDA
from
.nn
import
modules
from
.
import
cuda_setup
if
COMPILED_WITH_CUDA
:
from
.optim
import
adam
...
...
bitsandbytes/cextension.py
View file @
38092364
...
...
@@ -2,7 +2,7 @@ import ctypes as ct
import
os
from
warnings
import
warn
from
bitsandbytes.cuda_setup
import
evaluate_cuda_setup
from
bitsandbytes.cuda_setup
.main
import
evaluate_cuda_setup
class
CUDALibrary_Singleton
(
object
):
...
...
bitsandbytes/cuda_setup/__init__.py
0 → 100644
View file @
38092364
bitsandbytes/cuda_setup/compute_capability.py
0 → 100644
View file @
38092364
import
ctypes
from
dataclasses
import
dataclass
,
field
CUDA_SUCCESS
=
0
@
dataclass
class
CudaLibVals
:
# code bits taken from
# https://gist.github.com/f0k/63a664160d016a491b2cbea15913d549
nGpus
=
ctypes
.
c_int
()
cc_major
=
ctypes
.
c_int
()
cc_minor
=
ctypes
.
c_int
()
device
=
ctypes
.
c_int
()
error_str
=
ctypes
.
c_char_p
()
cuda
:
ctypes
.
CDLL
=
field
(
init
=
False
,
repr
=
False
)
ccs
:
List
[
str
,
...]
=
field
(
init
=
False
)
def
load_cuda_lib
(
self
):
"""
1. find libcuda.so library (GPU driver) (/usr/lib)
init_device -> init variables -> call function by reference
"""
libnames
=
(
"libcuda.so"
)
for
libname
in
libnames
:
try
:
self
.
cuda
=
ctypes
.
CDLL
(
libname
)
except
OSError
:
continue
else
:
break
else
:
raise
OSError
(
"could not load any of: "
+
" "
.
join
(
libnames
))
def
check_cuda_result
(
self
,
result_val
):
"""
2. call extern C function to determine CC
(see https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__DEVICE__DEPRECATED.html)
"""
cls_fields
:
Tuple
[
Field
,
...]
=
fields
(
self
.
__class__
)
if
result_val
!=
0
:
self
.
cuda
.
cuGetErrorString
(
result_val
,
ctypes
.
byref
(
self
.
error_str
))
print
(
"Count not initialize CUDA - failure!"
)
raise
Exception
(
"CUDA exception!"
)
return
result_val
def
__post_init__
(
self
):
self
.
load_cuda_lib
()
self
.
check_cuda_result
(
self
.
cuda
.
cuInit
(
0
))
self
.
check_cuda_result
(
self
.
cuda
,
self
.
cuda
.
cuDeviceGetCount
(
ctypes
.
byref
(
self
.
nGpus
)))
tmp_ccs
=
[]
for
gpu_index
in
range
(
self
.
nGpus
.
value
):
check_cuda_result
(
self
.
cuda
,
self
.
cuda
.
cuDeviceGet
(
ctypes
.
byref
(
self
.
device
),
gpu_index
)
)
check_cuda_result
(
self
.
cuda
,
self
.
cuda
.
cuDeviceComputeCapability
(
ctypes
.
byref
(
self
.
cc_major
),
ctypes
.
byref
(
self
.
cc_minor
),
self
.
device
),
)
tmp_ccs
.
append
(
f
"
{
self
.
cc_major
.
value
}
.
{
self
.
cc_minor
.
value
}
"
)
self
.
ccs
=
sorted
(
tmp_ccs
,
reverse
=
True
)
bitsandbytes/cuda_setup.py
→
bitsandbytes/cuda_setup
/main
.py
View file @
38092364
"""
extract factors the build is dependent on:
[X] compute capability
[X] compute capability
[ ] TODO: Q - What if we have multiple GPUs of different makes?
- CUDA version
- Software:
...
...
@@ -23,7 +23,7 @@ import os
from
pathlib
import
Path
from
typing
import
Set
,
Union
from
.utils
import
print_err
,
warn_of_missing_prerequisite
,
execute_and_return
from
.
.utils
import
print_err
,
warn_of_missing_prerequisite
,
execute_and_return
def
check_cuda_result
(
cuda
,
result_val
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment