Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_bios_ai_tuning.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7 __metaclass__ = type
8
9 ANSIBLE_METADATA = {'metadata_version': '1.1',
10 'status': ['preview'],
11 'supported_by': 'community'}
12
13 DOCUMENTATION = r'''
14 ---
15 module: intersight_bios_ai_tuning
16 short_description: AI-optimized BIOS policy presets for Cisco Intersight
17 description:
18 - Creates BIOS policies with pre-validated settings optimized for AI and GPU workloads.
19 - Provides named tuning profiles that set multiple BIOS knobs at once for common AI use cases.
20 - Profiles target NVIDIA H100/B200 GPU servers and Intel/AMD CPU platforms used in Cisco AI Factory.
21 - Individual BIOS knobs can be overridden after the preset is applied.
22 - For full BIOS knob control, use M(cisco.intersight.intersight_bios_policy) instead.
23 - For more information see L(Cisco Intersight,https://intersight.com/apidocs).
24 extends_documentation_fragment: intersight
25 options:
26 state:
27 description:
28 - If C(present), will verify the resource is present and will create if needed.
29 - If C(absent), will verify the resource is absent and will delete if needed.
30 type: str
31 choices: [present, absent]
32 default: present
33 organization:
34 description:
35 - The name of the Organization this resource is assigned to.
36 - Profiles and Policies that are created within a Custom Organization are applicable only to devices in the same Organization.
37 type: str
38 default: default
39 name:
40 description:
41 - The name assigned to the BIOS policy.
42 - The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_.
43 type: str
44 required: true
45 tags:
46 description:
47 - List of tags in Key:<user-defined key> Value:<user-defined value> format.
48 type: list
49 elements: dict
50 description:
51 description:
52 - The user-defined description of the BIOS policy.
53 type: str
54 aliases: [descr]
55 tuning_profile:
56 description:
57 - The AI tuning profile preset to apply.
58 - C(gpu_inference) optimizes for maximum GPU throughput with low-latency memory access.
59 Sets GPU ACS control enabled, NUMA optimized, hardware P-states disabled for consistent
60 performance, SR-IOV enabled, and memory interleave optimized.
61 - C(gpu_training) optimizes for large-scale GPU training workloads with maximum memory
62 bandwidth. Includes all gpu_inference settings plus maximum power performance tuning,
63 workload configuration set to balanced, and package C-state limit for sustained throughput.
64 - C(cpu_inference) optimizes for CPU-based inference with low-latency tuning.
65 Enables hardware P-states for native performance, Intel Turbo Boost, LLC prefetch,
66 and NUMA optimization without GPU-specific settings.
67 - C(edge_ai) optimizes for Cisco Unified Edge nodes with power-aware AI tuning.
68 Balances performance with power efficiency using energy-efficient turbo, hardware P-states,
69 and NUMA optimization suitable for edge deployment constraints.
70 type: str
71 choices: [gpu_inference, gpu_training, cpu_inference, edge_ai]
72 required: true
73 gpu_count:
74 description:
75 - Number of GPUs to enable via ACS Control (1-8).
76 - Only applicable for gpu_inference and gpu_training profiles.
77 - GPUs beyond this count will have ACS control set to platform-default.
78 type: int
79 default: 8
80 numa_optimized:
81 description:
82 - Override the NUMA optimization setting from the tuning profile.
83 type: str
84 choices: [platform-default, enabled, disabled]
85 cpu_power_management:
86 description:
87 - Override the CPU power management setting from the tuning profile.
88 type: str
89 choices: [platform-default, performance, energy-efficient, custom]
90 sriov:
91 description:
92 - Override the SR-IOV setting from the tuning profile.
93 - SR-IOV is required for GPU passthrough in virtualized environments.
94 type: str
95 choices: [platform-default, enabled, disabled]
96 intel_turbo_boost_tech:
97 description:
98 - Override the Intel Turbo Boost Technology setting.
99 type: str
100 choices: [platform-default, enabled, disabled]
101 cpu_performance:
102 description:
103 - Override the CPU performance setting from the tuning profile.
104 type: str
105 choices: [platform-default, custom, enterprise, high-throughput, hpc]
106 cpu_energy_performance:
107 description:
108 - Override the CPU energy performance bias setting.
109 type: str
110 choices: [platform-default, balanced-energy, balanced-performance, energy-efficient, performance]
111 author:
112 - Steve Fulmer (@stevefulme1)
113 '''
114
115 EXAMPLES = r'''
116 - name: Create GPU inference optimized BIOS policy for 8-GPU server
117 cisco.intersight.intersight_bios_ai_tuning:
118 api_private_key: "{{ api_private_key }}"
119 api_key_id: "{{ api_key_id }}"
120 organization: AI-Factory
121 name: bios-gpu-inference-h100
122 description: BIOS tuning for H100 GPU inference servers
123 tuning_profile: gpu_inference
124 gpu_count: 8
125
126 - name: Create GPU training BIOS policy with power override
127 cisco.intersight.intersight_bios_ai_tuning:
128 api_private_key: "{{ api_private_key }}"
129 api_key_id: "{{ api_key_id }}"
130 name: bios-gpu-training
131 tuning_profile: gpu_training
132 cpu_power_management: performance
133
134 - name: Create CPU inference BIOS policy for non-GPU workloads
135 cisco.intersight.intersight_bios_ai_tuning:
136 api_private_key: "{{ api_private_key }}"
137 api_key_id: "{{ api_key_id }}"
138 name: bios-cpu-inference
139 tuning_profile: cpu_inference
140 intel_turbo_boost_tech: enabled
141
142 - name: Create edge AI BIOS policy for Unified Edge nodes
143 cisco.intersight.intersight_bios_ai_tuning:
144 api_private_key: "{{ api_private_key }}"
145 api_key_id: "{{ api_key_id }}"
146 name: bios-edge-ai
147 tuning_profile: edge_ai
148 gpu_count: 2
149
150 - name: Delete AI BIOS policy
151 cisco.intersight.intersight_bios_ai_tuning:
152 api_private_key: "{{ api_private_key }}"
153 api_key_id: "{{ api_key_id }}"
154 name: bios-gpu-inference-h100
155 tuning_profile: gpu_inference
156 state: absent
157 '''
158
159 RETURN = r'''
160 api_response:
161 description: The API response output returned by the specified resource.
162 returned: always
163 type: dict
164 sample:
165 "api_response": {
166 "Name": "bios-gpu-inference-h100",
167 "ObjectType": "bios.Policy",
168 "NumaOptimized": "enabled",
169 "AcsControlGpu1state": "enabled"
170 }
171 applied_settings:
172 description: The BIOS settings applied by the tuning profile and any overrides.
173 returned: when state is present
174 type: dict
175 '''
176
177
178 from ansible.module_utils.basic import AnsibleModule
179 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
180
181
182 # AI tuning profile presets
183 # Each profile maps Intersight BIOS API property names to their values.
184 TUNING_PROFILES = {
185 'gpu_inference': {
186 # NUMA and memory optimization
187 'NumaOptimized': 'enabled',
188 'CbsDfCmnAcpiSratL3numa': 'enabled',
189 # CPU performance - disable P-states for consistent GPU-driven latency
190 'CpuPowerManagement': 'performance',
191 'CpuPerformance': 'high-throughput',
192 'CpuEnergyPerformance': 'performance',
193 'PackageCstateLimit': 'C0 C1 State',
194 'AutonomousCstateEnable': 'disabled',
195 'CpuHwpm': 'Disabled',
196 # GPU and I/O
197 'SrIov': 'enabled',
198 'AcsControlSlot11state': 'enabled',
199 'AcsControlSlot12state': 'enabled',
200 'AcsControlSlot13state': 'enabled',
201 'AcsControlSlot14state': 'enabled',
202 # Memory performance
203 'LlcPrefetch': 'enabled',
204 'XptPrefetch': 'enabled',
205 },
206 'gpu_training': {
207 # All gpu_inference settings plus maximum power
208 'NumaOptimized': 'enabled',
209 'CbsDfCmnAcpiSratL3numa': 'enabled',
210 'CpuPowerManagement': 'performance',
211 'CpuPerformance': 'high-throughput',
212 'CpuEnergyPerformance': 'performance',
213 'PackageCstateLimit': 'C0 C1 State',
214 'AutonomousCstateEnable': 'disabled',
215 'CpuHwpm': 'Disabled',
216 'SrIov': 'enabled',
217 'AcsControlSlot11state': 'enabled',
218 'AcsControlSlot12state': 'enabled',
219 'AcsControlSlot13state': 'enabled',
220 'AcsControlSlot14state': 'enabled',
221 'LlcPrefetch': 'enabled',
222 'XptPrefetch': 'enabled',
223 # Training-specific: maximum power and bandwidth
224 'WorkloadConfig': 'Balanced',
225 },
226 'cpu_inference': {
227 # CPU-optimized for inference without GPU focus
228 'NumaOptimized': 'enabled',
229 'CbsDfCmnAcpiSratL3numa': 'enabled',
230 'CpuPowerManagement': 'performance',
231 'CpuPerformance': 'high-throughput',
232 'CpuEnergyPerformance': 'performance',
233 'IntelTurboBoostTech': 'enabled',
234 'CpuHwpm': 'HWPM Native Mode',
235 'LlcPrefetch': 'enabled',
236 'XptPrefetch': 'enabled',
237 },
238 'edge_ai': {
239 # Power-aware AI tuning for edge nodes
240 'NumaOptimized': 'enabled',
241 'CpuPowerManagement': 'energy-efficient',
242 'CpuPerformance': 'enterprise',
243 'CpuEnergyPerformance': 'balanced-performance',
244 'EnergyEfficientTurbo': 'enabled',
245 'IntelTurboBoostTech': 'enabled',
246 'CpuHwpm': 'HWPM Native Mode',
247 'LlcPrefetch': 'enabled',
248 },
249 }
250
251 # GPU ACS control API property names by slot index (1-8)
252 GPU_ACS_PROPERTIES = [
253 'AcsControlGpu1state',
254 'AcsControlGpu2state',
255 'AcsControlGpu3state',
256 'AcsControlGpu4state',
257 'AcsControlGpu5state',
258 'AcsControlGpu6state',
259 'AcsControlGpu7state',
260 'AcsControlGpu8state',
261 ]
262
263 # Map of override parameter names to API property names
264 OVERRIDE_MAP = {
265 'numa_optimized': 'NumaOptimized',
266 'cpu_power_management': 'CpuPowerManagement',
267 'sriov': 'SrIov',
268 'intel_turbo_boost_tech': 'IntelTurboBoostTech',
269 'cpu_performance': 'CpuPerformance',
270 'cpu_energy_performance': 'CpuEnergyPerformance',
271 }
272
273
274 def main():
275 argument_spec = intersight_argument_spec.copy()
276 argument_spec.update(
277 state=dict(type='str', choices=['present', 'absent'], default='present'),
278 organization=dict(type='str', default='default'),
279 name=dict(type='str', required=True),
280 description=dict(type='str', aliases=['descr']),
281 tags=dict(type='list', elements='dict'),
282 tuning_profile=dict(type='str', choices=['gpu_inference', 'gpu_training', 'cpu_inference', 'edge_ai'], required=True),
283 gpu_count=dict(type='int', default=8),
284 numa_optimized=dict(type='str', choices=['platform-default', 'enabled', 'disabled']),
285 cpu_power_management=dict(type='str', choices=['platform-default', 'performance', 'energy-efficient', 'custom']),
286 sriov=dict(type='str', choices=['platform-default', 'enabled', 'disabled']),
287 intel_turbo_boost_tech=dict(type='str', choices=['platform-default', 'enabled', 'disabled']),
288 cpu_performance=dict(type='str', choices=['platform-default', 'custom', 'enterprise', 'high-throughput', 'hpc']),
289 cpu_energy_performance=dict(
290 type='str',
291 choices=['platform-default', 'balanced-energy', 'balanced-performance', 'energy-efficient', 'performance']
292 ),
293 )
294
295 module = AnsibleModule(
296 argument_spec,
297 supports_check_mode=True,
298 )
299
300 intersight = IntersightModule(module)
301 intersight.result['api_response'] = {}
302 intersight.result['trace_id'] = ''
303
304 resource_path = '/bios/Policies'
305
306 intersight.api_body = {
307 'Name': intersight.module.params['name'],
308 'Organization': {
309 'Name': intersight.module.params['organization'],
310 },
311 }
312
313 if module.params['state'] == 'present':
314 intersight.set_tags_and_description()
315
316 # Apply tuning profile preset
317 profile_name = module.params['tuning_profile']
318 profile_settings = TUNING_PROFILES[profile_name].copy()
319
320 # Apply GPU ACS control based on gpu_count for GPU profiles
321 if profile_name in ('gpu_inference', 'gpu_training'):
322 gpu_count = min(max(module.params['gpu_count'], 0), 8)
323 for i, prop in enumerate(GPU_ACS_PROPERTIES):
324 profile_settings[prop] = 'enabled' if i < gpu_count else 'platform-default'
325
326 # Apply user overrides
327 for param_name, api_property in OVERRIDE_MAP.items():
328 if module.params.get(param_name) is not None:
329 profile_settings[api_property] = module.params[param_name]
330
331 intersight.api_body.update(profile_settings)
332 intersight.result['applied_settings'] = profile_settings
333
334 intersight.configure_policy_or_profile(resource_path=resource_path)
335
336 module.exit_json(**intersight.result)
337
338
339 if __name__ == '__main__':
340 main()