Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
a3c9435d
Unverified
Commit
a3c9435d
authored
Jul 08, 2024
by
youkaichao
Committed by
GitHub
Jul 08, 2024
Browse files
[hardware][cuda] use device id under CUDA_VISIBLE_DEVICES for get_device_capability (#6216)
parent
4f0e0ea1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
4 deletions
+20
-4
vllm/platforms/cuda.py
vllm/platforms/cuda.py
+20
-4
No files found.
vllm/platforms/cuda.py
View file @
a3c9435d
...
...
@@ -2,6 +2,7 @@
pynvml. However, it should not initialize cuda context.
"""
import
os
from
functools
import
lru_cache
,
wraps
from
typing
import
Tuple
...
...
@@ -23,12 +24,27 @@ def with_nvml_context(fn):
return
wrapper
@
lru_cache
(
maxsize
=
8
)
@
with_nvml_context
def
get_physical_device_capability
(
device_id
:
int
=
0
)
->
Tuple
[
int
,
int
]:
handle
=
pynvml
.
nvmlDeviceGetHandleByIndex
(
device_id
)
return
pynvml
.
nvmlDeviceGetCudaComputeCapability
(
handle
)
def
device_id_to_physical_device_id
(
device_id
:
int
)
->
int
:
if
"CUDA_VISIBLE_DEVICES"
in
os
.
environ
:
device_ids
=
os
.
environ
[
"CUDA_VISIBLE_DEVICES"
].
split
(
","
)
device_ids
=
[
int
(
device_id
)
for
device_id
in
device_ids
]
physical_device_id
=
device_ids
[
device_id
]
else
:
physical_device_id
=
device_id
return
physical_device_id
class
CudaPlatform
(
Platform
):
_enum
=
PlatformEnum
.
CUDA
@
staticmethod
@
lru_cache
(
maxsize
=
8
)
@
with_nvml_context
def
get_device_capability
(
device_id
:
int
=
0
)
->
Tuple
[
int
,
int
]:
handle
=
pynvml
.
nvmlDeviceGetHandleByIndex
(
device_id
)
return
pynvml
.
nvmlDeviceGetCudaComputeCapability
(
handle
)
physical_device_id
=
device_id_to_physical_device_id
(
device_id
)
return
get_physical_device_capability
(
physical_device_id
)
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