MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / cuda_get_device_properties

Function cuda_get_device_properties

fastdeploy/usage/usage_lib.py:85–117  ·  view source on GitHub ↗

Get specified CUDA device property values without initializing CUDA in the current process.

(device, names: Sequence[str], init_cuda=False)

Source from the content-addressed store, hash-verified

83
84
85def cuda_get_device_properties(device, names: Sequence[str], init_cuda=False) -> tuple[Any, ...]:
86 """Get specified CUDA device property values without initializing CUDA in
87 the current process."""
88 if init_cuda or cuda_is_initialized():
89 try:
90 props = paddle.device.cuda.get_device_properties(device)
91 result = []
92 for name in names:
93 if name == "major":
94 value = props.major
95 elif name == "minor":
96 value = props.minor
97 elif name == "name":
98 value = props.name
99 elif name == "total_memory":
100 value = props.total_memory
101 elif name == "multi_processor_count":
102 value = props.multi_processor_count
103 else:
104 value = getattr(props, name)
105 result.append(value)
106 return tuple(result)
107 except Exception as e:
108 api_server_logger.debug(f"Warning: Failed to get CUDA properties: {e}")
109 return tuple([None] * len(names))
110
111 # Run in subprocess to avoid initializing CUDA as a side effect.
112 try:
113 mp_ctx = multiprocessing.get_context("spawn")
114 except ValueError:
115 mp_ctx = multiprocessing.get_context()
116 with ProcessPoolExecutor(max_workers=1, mp_context=mp_ctx) as executor:
117 return executor.submit(cuda_get_device_properties, device, names, True).result()
118
119
120def get_xpu_model():

Callers 2

test_cuda_initializedMethod · 0.90
_report_usage_onceMethod · 0.85

Calls 3

cuda_is_initializedFunction · 0.85
debugMethod · 0.80
resultMethod · 0.45

Tested by 1

test_cuda_initializedMethod · 0.72