Skip to content

Commit aafedf4

Browse files
committed
NV-CONTROL: query target count
1 parent 98f45f0 commit aafedf4

2 files changed

Lines changed: 73 additions & 34 deletions

File tree

‎Xlib/ext/nvcontrol.py‎

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@
2727
extname = 'NV-CONTROL'
2828

2929

30+
def query_target_count(self, target):
31+
"""return the target count"""
32+
reply = NVCtrlQueryTargetCountRequest(display=self.display,
33+
opcode=self.display.get_extension_major(extname),
34+
target_type=target.type())
35+
return int(reply._data.get('count'))
36+
37+
38+
def get_gpu_count(self):
39+
"""Return the number of GPU's present in the system."""
40+
return int(query_target_count(self, Gpu()))
41+
42+
3043
def query_int_attribute(self, target, displays, attr):
3144
"""return the value of an integer attribute"""
3245
display_mask = _displays2mask(displays)
@@ -54,10 +67,6 @@ def set_int_attribute(self, target, displays, attr, value):
5467
return reply._data.get('flags')
5568

5669

57-
def set_cooler_manual_control_enabled(self, target, enabled):
58-
return set_int_attribute(self, target, [], NV_CTRL_GPU_COOLER_MANUAL_CONTROL, 1 if enabled else 0) == 1
59-
60-
6170
def query_string_attribute(self, target, displays, attr):
6271
"""return the value of an integer attribute"""
6372
display_mask = _displays2mask(displays)
@@ -200,6 +209,10 @@ def get_cooler_manual_control_enabled(self, target):
200209
return query_int_attribute(self, target, [], NV_CTRL_GPU_COOLER_MANUAL_CONTROL) == 1
201210

202211

212+
def set_cooler_manual_control_enabled(self, target, enabled):
213+
return set_int_attribute(self, target, [], NV_CTRL_GPU_COOLER_MANUAL_CONTROL, 1 if enabled else 0) == 1
214+
215+
203216
def get_fan_duty(self, target):
204217
return query_int_attribute(self, target, [], NV_CTRL_THERMAL_COOLER_CURRENT_LEVEL)
205218

@@ -259,8 +272,10 @@ def _displays2mask(displays):
259272

260273

261274
def init(disp, info):
275+
disp.extension_add_method('display', 'nvcontrol_query_target_count', query_target_count)
262276
disp.extension_add_method('display', 'nvcontrol_query_int_attribute', query_int_attribute)
263277
disp.extension_add_method('display', 'nvcontrol_query_string_attribute', query_string_attribute)
278+
disp.extension_add_method('display', 'nvcontrol_get_gpu_count', get_gpu_count)
264279
disp.extension_add_method('display', 'nvcontrol_get_vram', get_vram)
265280
disp.extension_add_method('display', 'nvcontrol_get_irq', get_irq)
266281
disp.extension_add_method('display', 'nvcontrol_supports_framelock', supports_framelock)
@@ -5186,3 +5201,24 @@ class NVCtrlQueryStringAttributeRequest(rq.ReplyRequest):
51865201
rq.Card32('pad7'),
51875202
rq.String8('string'),
51885203
)
5204+
5205+
5206+
class NVCtrlQueryTargetCountRequest(rq.ReplyRequest):
5207+
_request = rq.Struct(
5208+
rq.Card8('opcode'),
5209+
rq.Opcode(X_nvCtrlQueryTargetCount),
5210+
rq.RequestLength(),
5211+
rq.Card32('target_type'),
5212+
)
5213+
_reply = rq.Struct(
5214+
rq.ReplyCode(),
5215+
rq.Card8('padb1'),
5216+
rq.Card16('sequence_number'),
5217+
rq.ReplyLength(),
5218+
rq.Card32('count'),
5219+
rq.Card32('pad4'),
5220+
rq.Card32('pad5'),
5221+
rq.Card32('pad6'),
5222+
rq.Card32('pad7'),
5223+
rq.Card32('pad8'),
5224+
)

‎examples/nvcontrol.py‎

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,36 +50,39 @@
5050
gpu = Gpu(0)
5151
fan = Cooler(0)
5252

53-
dic = {'get_vram': display.nvcontrol_get_vram(gpu),
54-
'get_irq': display.nvcontrol_get_irq(gpu),
55-
'supports_framelock': display.nvcontrol_supports_framelock(gpu),
56-
'get_core_temp': display.nvcontrol_get_core_temp(gpu),
57-
'get_core_threshold': display.nvcontrol_get_core_threshold(gpu),
58-
'get_default_core_threshold': display.nvcontrol_get_default_core_threshold(gpu),
59-
'get_max_core_threshold': display.nvcontrol_get_max_core_threshold(gpu),
60-
'get_ambient_temp': display.nvcontrol_get_ambient_temp(gpu),
61-
'get_cuda_cores': display.nvcontrol_get_cuda_cores(gpu),
62-
'get_memory_bus_width': display.nvcontrol_get_memory_bus_width(gpu),
63-
'get_total_dedicated_gpu_memory': display.nvcontrol_get_total_dedicated_gpu_memory(gpu),
64-
'get_used_dedicated_gpu_memory': display.nvcontrol_get_used_dedicated_gpu_memory(gpu),
65-
'get_pcie_current_link_width': display.nvcontrol_get_pcie_current_link_width(gpu),
66-
'get_pcie_max_link_width': display.nvcontrol_get_pcie_max_link_width(gpu),
67-
'get_pcie_generation': display.nvcontrol_get_pcie_generation(gpu),
68-
'get_video_encoder_utilization': display.nvcontrol_get_video_encoder_utilization(gpu),
69-
'get_video_decoder_utilization': display.nvcontrol_get_video_decoder_utilization(gpu),
70-
'get_current_performance_level': display.nvcontrol_get_current_performance_level(gpu),
71-
'get_gpu_nvclock_offset': display.nvcontrol_get_gpu_nvclock_offset(gpu),
72-
'get_mem_transfer_rate_offset': display.nvcontrol_get_mem_transfer_rate_offset(gpu),
73-
'get_cooler_manual_control_enabled': display.nvcontrol_get_cooler_manual_control_enabled(gpu),
74-
'get_fan_duty': display.nvcontrol_get_fan_duty(fan),
75-
'get_fan_rpm': display.nvcontrol_get_fan_rpm(fan),
76-
'get_max_displays': display.nvcontrol_get_max_displays(gpu),
77-
'get_name': display.nvcontrol_get_name(gpu),
78-
'get_driver_version': display.nvcontrol_get_driver_version(gpu),
79-
'get_vbios_version': display.nvcontrol_get_vbios_version(gpu),
80-
'get_gpu_uuid': display.nvcontrol_get_gpu_uuid(gpu),
81-
'get_gpu_utilization': display.nvcontrol_get_gpu_utilization(gpu),
82-
'get_performance_modes': display.nvcontrol_get_performance_modes(gpu)}
53+
dic = {
54+
'get_gpu_count': display.nvcontrol_get_gpu_count(),
55+
'get_vram': display.nvcontrol_get_vram(gpu),
56+
'get_irq': display.nvcontrol_get_irq(gpu),
57+
'supports_framelock': display.nvcontrol_supports_framelock(gpu),
58+
'get_core_temp': display.nvcontrol_get_core_temp(gpu),
59+
'get_core_threshold': display.nvcontrol_get_core_threshold(gpu),
60+
'get_default_core_threshold': display.nvcontrol_get_default_core_threshold(gpu),
61+
'get_max_core_threshold': display.nvcontrol_get_max_core_threshold(gpu),
62+
'get_ambient_temp': display.nvcontrol_get_ambient_temp(gpu),
63+
'get_cuda_cores': display.nvcontrol_get_cuda_cores(gpu),
64+
'get_memory_bus_width': display.nvcontrol_get_memory_bus_width(gpu),
65+
'get_total_dedicated_gpu_memory': display.nvcontrol_get_total_dedicated_gpu_memory(gpu),
66+
'get_used_dedicated_gpu_memory': display.nvcontrol_get_used_dedicated_gpu_memory(gpu),
67+
'get_pcie_current_link_width': display.nvcontrol_get_pcie_current_link_width(gpu),
68+
'get_pcie_max_link_width': display.nvcontrol_get_pcie_max_link_width(gpu),
69+
'get_pcie_generation': display.nvcontrol_get_pcie_generation(gpu),
70+
'get_video_encoder_utilization': display.nvcontrol_get_video_encoder_utilization(gpu),
71+
'get_video_decoder_utilization': display.nvcontrol_get_video_decoder_utilization(gpu),
72+
'get_current_performance_level': display.nvcontrol_get_current_performance_level(gpu),
73+
'get_gpu_nvclock_offset': display.nvcontrol_get_gpu_nvclock_offset(gpu),
74+
'get_mem_transfer_rate_offset': display.nvcontrol_get_mem_transfer_rate_offset(gpu),
75+
'get_cooler_manual_control_enabled': display.nvcontrol_get_cooler_manual_control_enabled(gpu),
76+
'get_fan_duty': display.nvcontrol_get_fan_duty(fan),
77+
'get_fan_rpm': display.nvcontrol_get_fan_rpm(fan),
78+
'get_max_displays': display.nvcontrol_get_max_displays(gpu),
79+
'get_name': display.nvcontrol_get_name(gpu),
80+
'get_driver_version': display.nvcontrol_get_driver_version(gpu),
81+
'get_vbios_version': display.nvcontrol_get_vbios_version(gpu),
82+
'get_gpu_uuid': display.nvcontrol_get_gpu_uuid(gpu),
83+
'get_gpu_utilization': display.nvcontrol_get_gpu_utilization(gpu),
84+
'get_performance_modes': display.nvcontrol_get_performance_modes(gpu)
85+
}
8386

8487
pprint(dic)
8588

0 commit comments

Comments
 (0)