From afaaef8d1f8ba39cf81fed5eef7de45bfc9863bd Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Tue, 23 Jul 2024 16:07:16 +0500 Subject: [PATCH 1/4] Render gpu ref appropriately --- catalog_reader/questions.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/catalog_reader/questions.py b/catalog_reader/questions.py index 12a6440..478c597 100644 --- a/catalog_reader/questions.py +++ b/catalog_reader/questions.py @@ -35,7 +35,42 @@ def normalize_question(question: dict, version_data: dict, context: dict) -> Non data['enum'] = [ {'value': i, 'description': f'{i!r} Interface'} for i in context['nic_choices'] ] - elif ref == 'definitions/gpuConfiguration': + elif ref == 'definitions/gpu_configuration': + # How we will go about this is the following: + # If user has only nvidia gpus and we are able to retrieve nvidia gpu's uuid + # we will allow user to select any of the available nvidia gpu + # If user has any other GPU apart from nvidia vendor, he will have to passthrough all available gpus + # If user has nvidia + other gpu's, then we can show a boolean or a string enum + # highlighting the nvidia bits + gpu_choices = {entry for entry in context['gpu_choices'] if entry['gpu_details']['available_to_host']} + show_all_gpus_flag = any( + g['vendor'] != 'NVIDIA' or not g['vendor_specific_config'].get('uuid') for g in gpu_choices + ) + show_nvidia_selection = any( + g['vendor'] == 'NVIDIA' and g['vendor_specific_config'].get('uuid') for g in gpu_choices + ) + data['attrs'] = [ + { + 'variable': 'use_all_gpus', + 'label': 'Passthrough available GPUs', + 'description': 'Please select this option to passthrough all available GPUs to the app', + 'schema': { + 'type': 'boolean', + 'default': False, + 'hidden': not show_all_gpus_flag, + } + }, + { + 'variable': 'nvidia_gpu_selection', + 'label': 'Select NVIDIA GPU', + 'description': 'Please select the NVIDIA GPU to passthrough to the app', + 'schema': { + 'type': 'dict', + 'attrs': [] + }, + } + ] + data['attrs'] = [ { 'variable': gpu, From 4e9a6de769d660d658e84e16a212b4980bb718b6 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Wed, 24 Jul 2024 08:36:04 +0500 Subject: [PATCH 2/4] Fix default questions context --- catalog_reader/app_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/catalog_reader/app_utils.py b/catalog_reader/app_utils.py index d33e000..0af0195 100644 --- a/catalog_reader/app_utils.py +++ b/catalog_reader/app_utils.py @@ -31,13 +31,13 @@ def get_app_details_base(retrieve_complete_item_keys: bool = True) -> dict: def get_default_questions_context() -> dict: return { - 'gpus': {}, 'timezones': {'Asia/Saigon': 'Asia/Saigon', 'Asia/Damascus': 'Asia/Damascus'}, 'ip_choices': {'192.168.0.10': '192.168.0.10', '0.0.0.0': '0.0.0.0'}, 'certificates': [], 'certificate_authorities': [], 'system.general.config': {'timezone': 'America/Los_Angeles'}, 'unused_ports': [i for i in range(1025, 65535)], + 'gpu_choices': {} } From e80de3e7d2cc8aecdd2d9944ad1a4d41c947a57f Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Wed, 24 Jul 2024 09:27:58 +0500 Subject: [PATCH 3/4] Properly render gpu schema --- catalog_reader/questions.py | 58 +++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/catalog_reader/questions.py b/catalog_reader/questions.py index 478c597..9b190cc 100644 --- a/catalog_reader/questions.py +++ b/catalog_reader/questions.py @@ -42,7 +42,7 @@ def normalize_question(question: dict, version_data: dict, context: dict) -> Non # If user has any other GPU apart from nvidia vendor, he will have to passthrough all available gpus # If user has nvidia + other gpu's, then we can show a boolean or a string enum # highlighting the nvidia bits - gpu_choices = {entry for entry in context['gpu_choices'] if entry['gpu_details']['available_to_host']} + gpu_choices = [entry for entry in context['gpu_choices'] if entry['gpu_details']['available_to_host']] show_all_gpus_flag = any( g['vendor'] != 'NVIDIA' or not g['vendor_specific_config'].get('uuid') for g in gpu_choices ) @@ -62,31 +62,47 @@ def normalize_question(question: dict, version_data: dict, context: dict) -> Non }, { 'variable': 'nvidia_gpu_selection', - 'label': 'Select NVIDIA GPU', - 'description': 'Please select the NVIDIA GPU to passthrough to the app', + 'label': 'Select NVIDIA GPU(s)', + 'description': 'Please select the NVIDIA GPU(s) to passthrough to the app', 'schema': { 'type': 'dict', - 'attrs': [] + 'additional_attrs': True, + 'hidden': not show_nvidia_selection, + 'attrs': [ + { + 'variable': gpu['gpu_details']['addr']['pci_slot'], + 'label': gpu['description'], + 'description': f'NVIDIA gpu {gpu["vendor_specific_config"]["uuid"]}', + 'schema': { + 'type': 'dict', + 'attrs': [ + { + 'variable': 'uuid', + 'schema': { + 'type': 'string', + 'default': gpu['vendor_specific_config']['uuid'], + 'hidden': True, + } + }, + { + 'variable': 'use_gpu', + 'label': 'Use this GPU', + 'description': 'Use this GPU for the app', + 'schema': { + 'type': 'boolean', + 'default': False, + } + } + ], + } + } + for gpu in (gpu_choices if show_nvidia_selection else []) + if gpu['vendor'] == 'NVIDIA' and gpu['vendor_specific_config'].get('uuid') + ] }, - } + }, ] - data['attrs'] = [ - { - 'variable': gpu, - 'label': f'GPU Resource ({gpu})', - 'description': 'Please enter the number of GPUs to allocate', - 'schema': { - 'type': 'int', - 'max': int(quantity), - 'enum': [ - {'value': i, 'description': f'Allocate {i!r} {gpu} GPU'} - for i in range(int(quantity) + 1) - ], - 'default': 0, - } - } for gpu, quantity in context['gpus'].items() - ] elif ref == 'definitions/timezone': data.update({ 'enum': [{'value': t, 'description': f'{t!r} timezone'} for t in sorted(context['timezones'])], From eed43d1436676ee2e86a49f8fa53dc85d765f714 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Wed, 24 Jul 2024 20:59:45 +0500 Subject: [PATCH 4/4] Fix wording --- catalog_reader/questions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/catalog_reader/questions.py b/catalog_reader/questions.py index 9b190cc..20decce 100644 --- a/catalog_reader/questions.py +++ b/catalog_reader/questions.py @@ -52,8 +52,8 @@ def normalize_question(question: dict, version_data: dict, context: dict) -> Non data['attrs'] = [ { 'variable': 'use_all_gpus', - 'label': 'Passthrough available GPUs', - 'description': 'Please select this option to passthrough all available GPUs to the app', + 'label': 'Passthrough available (non-NVIDIA) GPUs', + 'description': 'Please select this option to passthrough all (non-NVIDIA) GPUs to the app', 'schema': { 'type': 'boolean', 'default': False,