From 309d9cde6e1fa9abe3eda469dae47b9bcb82fe00 Mon Sep 17 00:00:00 2001
From: Patrice RINGOT <patrice.ringot@loria.fr>
Date: Wed, 7 Aug 2019 23:00:11 +0200
Subject: [PATCH] [gen:oar-properties] use the new GPU representation

---
 lib/refrepo/gen/oar-properties.rb             |  8 ++--
 .../gen/wiki/generators/site_hardware.rb      | 42 +-----------------
 lib/refrepo/gpu_ref.rb                        | 44 +++++++++++++++++++
 3 files changed, 50 insertions(+), 44 deletions(-)
 create mode 100644 lib/refrepo/gpu_ref.rb

diff --git a/lib/refrepo/gen/oar-properties.rb b/lib/refrepo/gen/oar-properties.rb
index b76919f2a4f..ff1167db2d1 100644
--- a/lib/refrepo/gen/oar-properties.rb
+++ b/lib/refrepo/gen/oar-properties.rb
@@ -3,6 +3,7 @@
 require 'hashdiff'
 require 'refrepo/data_loader'
 require 'net/ssh'
+require 'refrepo/gpu_ref'
 
 class MissingProperty < StandardError; end
 
@@ -125,9 +126,10 @@ def get_ref_node_properties_internal(cluster_uid, cluster, node_uid, node)
   h['memcpu'] = node['main_memory']['ram_size'] / node['architecture']['nb_procs']/MiB
   h['memnode'] = node['main_memory']['ram_size'] / MiB
 
-  if node.key?('gpu') && node['gpu']['gpu'] == true
-    h['gpu_model'] = node['gpu']['gpu_model']
-    h['gpu_count'] = node['gpu']['gpu_count']
+  if node.key?('gpu_devices')
+    # This forbids a node to host different GPU models ...
+    h['gpu_model'] = GPURef.getGrid5000LegacyNameFor(node['gpu_devices'].values[0]['model'])
+    h['gpu_count'] = node['gpu_devices'].length
   else
     h['gpu_model'] = false
     h['gpu_count'] = 0
diff --git a/lib/refrepo/gen/wiki/generators/site_hardware.rb b/lib/refrepo/gen/wiki/generators/site_hardware.rb
index fd7aeca20c9..f358ddb1116 100644
--- a/lib/refrepo/gen/wiki/generators/site_hardware.rb
+++ b/lib/refrepo/gen/wiki/generators/site_hardware.rb
@@ -1,46 +1,6 @@
 # coding: utf-8
 
-class GPURef
-  @@gpu2cores = {
-    "GeForce RTX 2080 Ti" => 4352,
-    "GeForce GTX 1080 Ti" => 3584,
-    "Tesla P100-PCIE-16GB" => 3584,
-    "Tesla V100-PCIE-32GB" => 5120,
-    "Tesla M2075" => 448,
-    "GeForce GTX TITAN Black" => 2880,
-    "GeForce GTX 980" => 2048,
-    "Tesla K40m" => 2880,
-  }
-
-  @@new_gpu_names2old_ones = {
-    "GeForce RTX 2080 Ti" => "RTX 2080 Ti",
-    "GeForce GTX 1080 Ti" => "GTX 1080 Ti",
-    "Tesla P100-PCIE-16GB" => "Tesla P100",
-    "Tesla V100-PCIE-32GB" => "Tesla V100",
-    "Tesla M2075" => "Tesla M2075",
-    "GeForce GTX TITAN Black" => "Titan Black",
-    "GeForce GTX 980" => "GTX 980",
-    "Tesla K40m" => "Tesla K40M",
-  }
-
-  def self.getNumberOfCoresFor(model)
-    if @@gpu2cores[model]
-      return @@gpu2cores[model]
-    else
-      raise "Fix me: #{model} is missing"
-    end
-  end
-
-  # will not keep this, just to ease manual testing for bug #10436
-  def self.getGrid5000LegacyNameFor(model)
-    if @@new_gpu_names2old_ones[model]
-      return @@new_gpu_names2old_ones[model]
-    else
-      return model
-    end
-  end
-
-end
+require 'refrepo/gpu_ref'
 
 class SiteHardwareGenerator < WikiGenerator
 
diff --git a/lib/refrepo/gpu_ref.rb b/lib/refrepo/gpu_ref.rb
new file mode 100644
index 00000000000..48cb3fad7ae
--- /dev/null
+++ b/lib/refrepo/gpu_ref.rb
@@ -0,0 +1,44 @@
+# coding: utf-8
+
+class GPURef
+  @@gpu2cores = {
+    "GeForce RTX 2080 Ti" => 4352,
+    "GeForce GTX 1080 Ti" => 3584,
+    "Tesla P100-PCIE-16GB" => 3584,
+    "Tesla V100-PCIE-32GB" => 5120,
+    "Tesla M2075" => 448,
+    "GeForce GTX TITAN Black" => 2880,
+    "GeForce GTX 980" => 2048,
+    "Tesla K40m" => 2880,
+  }
+
+  @@new_gpu_names2old_ones = {
+    "GeForce RTX 2080 Ti" => "RTX 2080 Ti",
+    "GeForce GTX 1080 Ti" => "GTX 1080 Ti",
+    "Tesla P100-PCIE-16GB" => "Tesla P100",
+    "Tesla V100-PCIE-32GB" => "Tesla V100",
+    "Tesla M2075" => "Tesla M2075",
+    "GeForce GTX TITAN Black" => "Titan Black",
+    "GeForce GTX 980" => "GTX 980",
+    "Tesla K40m" => "Tesla K40M",
+  }
+
+  def self.getNumberOfCoresFor(model)
+    if @@gpu2cores[model]
+      return @@gpu2cores[model]
+    else
+      raise "Fix me: #{model} is missing"
+    end
+  end
+
+  # will not keep this, just to ease manual testing for bug #10436
+  def self.getGrid5000LegacyNameFor(model)
+    if @@new_gpu_names2old_ones[model]
+      return @@new_gpu_names2old_ones[model]
+    else
+      return model
+    end
+  end
+
+end
+
-- 
GitLab