From ac4cfb7df5975cd2bcd44b2743c671ce7c347023 Mon Sep 17 00:00:00 2001
From: Lucas Nussbaum <lucas.nussbaum@loria.fr>
Date: Sun, 19 Jan 2020 15:51:04 +0100
Subject: [PATCH] [oar-prop] Add support for cores_affinity key in GPU
 definition

---
 lib/refrepo/gen/oar-properties.rb | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lib/refrepo/gen/oar-properties.rb b/lib/refrepo/gen/oar-properties.rb
index b4655b3cb12..7a47b84b009 100644
--- a/lib/refrepo/gen/oar-properties.rb
+++ b/lib/refrepo/gen/oar-properties.rb
@@ -1404,8 +1404,16 @@ def extract_clusters_description(clusters, site_name, options, data_hierarchy, s
             numa_gpus = node_description["gpu_devices"].values.select {|v| v['cpu_affinity'] == cpu_num and v.fetch("reservation", true)}
 
             if not numa_gpus.empty? # this can happen if GPUs are not reservable
-              gpu_idx = core_num / (phys_rsc_map["core"][:per_server_count] / numa_gpus.length)
-              selected_gpu = numa_gpus[gpu_idx]
+              if numa_gpus.first.key? 'cores_affinity'
+                # this cluster uses cores_affinity, not arbitrary allocation
+                selected_gpu = numa_gpus.find { |g| g['cores_affinity'].split.map { |e| e.to_i }.include?(row[:cpuset]) }
+                if selected_gpu.nil?
+                  raise "Could not find a GPU on CPU #{cpu_num} for core #{row[:cpuset]}"
+                end
+              else
+                gpu_idx = core_num / (phys_rsc_map["core"][:per_server_count] / numa_gpus.length)
+                selected_gpu = numa_gpus[gpu_idx]
+              end
               # id of the selected GPU in the node
               local_id = node_description["gpu_devices"].values.index(selected_gpu)
 
-- 
GitLab