Skip to content

Commit bc5a45b

Browse files
Dynamic CPU/GPU option
1 parent 1deb0af commit bc5a45b

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

nebula/controller.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def __init__(self, args):
8080
self.n_nodes = 0
8181
self.mender = None if self.simulation else Mender()
8282
self.use_blockchain = args.use_blockchain if hasattr(args, "use_blockchain") else False
83+
self.gpu_available = False
8384

8485
def start(self):
8586
banner = """
@@ -334,6 +335,7 @@ def run_frontend(self):
334335
- ./config/nebula:/etc/nginx/sites-available/default
335336
environment:
336337
- NEBULA_PRODUCTION={production}
338+
- NEBULA_GPU_AVAILABLE={gpu_available}
337339
- NEBULA_ADVANCED_ANALYTICS={advanced_analytics}
338340
- SERVER_LOG=/nebula/app/logs/server.log
339341
- NEBULA_LOGS_DIR=/nebula/app/logs/
@@ -377,10 +379,16 @@ def run_frontend(self):
377379
external: true
378380
"""
379381
)
382+
383+
try:
384+
subprocess.check_call(["nvidia-smi"])
385+
self.gpu_available = True
386+
except Exception as e:
387+
logging.info("No GPU available for the frontend, nodes will be deploy in CPU mode")
380388

381389
# Generate the Docker Compose file dynamically
382390
services = ""
383-
services += frontend_template.format(production=self.production, advanced_analytics=self.advanced_analytics, path=self.root_path, gw="192.168.10.1", ip="192.168.10.100", frontend_port=self.frontend_port, statistics_port=self.statistics_port)
391+
services += frontend_template.format(production=self.production, gpu_available=self.gpu_available, advanced_analytics=self.advanced_analytics, path=self.root_path, gw="192.168.10.1", ip="192.168.10.100", frontend_port=self.frontend_port, statistics_port=self.statistics_port)
384392
docker_compose_file = docker_compose_template.format(services)
385393

386394
if self.production:

nebula/frontend/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
class Settings:
5959
production: bool = os.environ.get("NEBULA_PRODUCTION", "False") == "True"
60+
gpu_available: bool = os.environ.get("NEBULA_GPU_AVAILABLE", "False") == "True"
6061
advanced_analytics: bool = os.environ.get("NEBULA_ADVANCED_ANALYTICS", "False") == "True"
6162
log_dir: str = os.environ.get("NEBULA_LOGS_DIR")
6263
config_dir: str = os.environ.get("NEBULA_CONFIG_DIR")
@@ -933,7 +934,7 @@ async def nebula_dashboard_download_logs_metrics(scenario_name: str, request: Re
933934
@app.get("/nebula/dashboard/deployment/", response_class=HTMLResponse)
934935
async def nebula_dashboard_deployment(request: Request, session: Dict = Depends(get_session)):
935936
scenario_running = get_running_scenario()
936-
return templates.TemplateResponse("deployment.html", {"request": request, "scenario_running": scenario_running, "user_logged_in": session.get("user")})
937+
return templates.TemplateResponse("deployment.html", {"request": request, "scenario_running": scenario_running, "user_logged_in": session.get("user"), "gpu_available": settings.gpu_available})
937938

938939

939940
def attack_node_assign(

nebula/frontend/templates/deployment.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,12 @@ <h5 class="step-title">Accelerator definition</h5>
450450
<div class="form-check">
451451
<select class="form-control" id="resourceUsage" name="resources"
452452
style="display: inline; width: 20%">
453+
{% if gpu_available %}
453454
<option value="gpu" selected>GPU</option>
454455
<option value="cpu">CPU</option>
456+
{% else %}
457+
<option value="cpu" selected>CPU</option>
458+
{% endif %}
455459
</select>
456460
</div>
457461
</div>

0 commit comments

Comments
 (0)