From 61a5b4bd4d4471a3c52146508af0c3dca93f9a41 Mon Sep 17 00:00:00 2001
From: Lucas Nussbaum <lucas.nussbaum@loria.fr>
Date: Wed, 1 Jul 2020 16:59:47 +0200
Subject: [PATCH] [dev/oar-prop] Improve assignment of GPU ids

---
 lib/refrepo/gen/oar-properties.rb | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/refrepo/gen/oar-properties.rb b/lib/refrepo/gen/oar-properties.rb
index 640f18e483..cbcdf9b2e3 100644
--- a/lib/refrepo/gen/oar-properties.rb
+++ b/lib/refrepo/gen/oar-properties.rb
@@ -1432,7 +1432,13 @@ def extract_clusters_description(clusters, site_name, options, data_hierarchy, s
               # id of the selected GPU in the node
               local_id = node_description["gpu_devices"].values.index(selected_gpu)
 
-              row[:gpu] = phys_rsc_map["gpu"][:current_ids][node_index0 * gpu_count + local_id]
+              # to assign the gpu number, just use the number of nodes and the number of GPUs per node
+              # sanity check: we must fall into the correct range
+              gpu = phys_rsc_map["gpu"][:current_ids].min + node_index0 * gpu_count + local_id
+              if gpu > phys_rsc_map["gpu"][:current_ids].max
+                raise "Invalid GPU number for cluster #{cluster_name}"
+              end
+              row[:gpu] = gpu
               row[:gpudevice] = local_id
               row[:gpudevicepath] = selected_gpu['device']
               row[:gpumodel] = selected_gpu['model']
-- 
GitLab