forked from netease-youdao/QAnything
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Optimize the way to obtain GPU computing power.
- Loading branch information
1 parent
bf66629
commit 8a051e5
Showing
3 changed files
with
36 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pycuda.driver as cuda | ||
import pycuda.autoinit | ||
import sys # 导入sys模块来读取命令行参数 | ||
|
||
def get_cuda_device_major_minor(device_id=0): | ||
cuda.init() | ||
device = cuda.Device(device_id) | ||
attributes = device.get_attributes() | ||
major = attributes[cuda.device_attribute.COMPUTE_CAPABILITY_MAJOR] | ||
minor = attributes[cuda.device_attribute.COMPUTE_CAPABILITY_MINOR] | ||
cmp_ver = f"{major}.{minor}" | ||
return cmp_ver | ||
|
||
# 从命令行参数获取设备号 | ||
device_id = 0 # 默认设备号 | ||
if len(sys.argv) > 1: | ||
device_id = int(sys.argv[1]) # 将传入的参数转换为整数 | ||
|
||
cmp_ver = get_cuda_device_major_minor(device_id) | ||
print(cmp_ver) # 打印结果以便在Shell中捕获 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters