-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-130121 / 24.10 / Add support for GPU ref (#14071)
* Add type hints for nvidia gpu util func * Add util function which normalizes gpu details and gives us the data we need to expose gpu resources * Add public endpoint which exposes gpus which can be consumed by apps * Add gpu stuff to questions context * Mark update as true for config * Properly get normalized gpus for apps * Normalize gpu ref value * Fix conditional for non-nvidia gpus
- Loading branch information
Showing
6 changed files
with
103 additions
and
5 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
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
56 changes: 56 additions & 0 deletions
56
src/middlewared/middlewared/plugins/apps/resources_utils.py
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,56 @@ | ||
def get_gpu_base_dict() -> dict: | ||
return { | ||
'vendor': '', | ||
'description': '', | ||
'error': None, | ||
'vendor_specific_config': {}, | ||
'gpu_details': {}, | ||
'pci_slot': None, | ||
} | ||
|
||
|
||
def get_normalized_gpu_choices(all_gpus_info: list[dict], nvidia_gpus: dict) -> list[dict]: | ||
all_gpus_info = {gpu['addr']['pci_slot']: gpu for gpu in all_gpus_info} | ||
gpus = [] | ||
for pci_slot, gpu_info in all_gpus_info.items(): | ||
gpu_config = get_gpu_base_dict() | { | ||
'vendor': gpu_info['vendor'], | ||
'description': gpu_info['description'], | ||
'gpu_details': gpu_info, | ||
'pci_slot': pci_slot, | ||
} | ||
gpus.append(gpu_config) | ||
|
||
if gpu_info['vendor'] == 'NVIDIA': | ||
if pci_slot not in nvidia_gpus: | ||
gpu_config.update({ | ||
'error': 'Unable to locate GPU details from procfs', | ||
}) | ||
continue | ||
|
||
nvidia_gpu = nvidia_gpus[pci_slot] | ||
error = None | ||
if not nvidia_gpu.get('gpu_uuid'): | ||
error = 'GPU UUID not found' | ||
elif '?' in nvidia_gpu['gpu_uuid']: | ||
error = 'Malformed GPU UUID found' | ||
if error: | ||
gpu_config.update({ | ||
'error': error, | ||
'nvidia_gpu_details': nvidia_gpu, | ||
}) | ||
continue | ||
|
||
gpu_config.update({ | ||
'vendor_specific_config': { | ||
'uuid': nvidia_gpu['gpu_uuid'], | ||
}, | ||
'description': nvidia_gpu.get('model') or gpu_config['description'], | ||
}) | ||
|
||
if not gpu_info['available_to_host']: | ||
gpu_config.update({ | ||
'error': 'GPU not available to host', | ||
}) | ||
|
||
return gpus |
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
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