From 5e87d35299642269eead5b72e65f7d919d18d040 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Thu, 16 Sep 2010 19:48:34 +0000
Subject: [PATCH] add support for a GRES numeric suffix of "G" (in addition to
 "G" and "K" previously supported).

---
 doc/man/man5/gres.conf.5  |  5 +++--
 doc/man/man5/slurm.conf.5 |  4 +++-
 src/common/gres.c         | 10 ++++++++++
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/doc/man/man5/gres.conf.5 b/doc/man/man5/gres.conf.5
index 301fcb0241d..1b2382456bb 100644
--- a/doc/man/man5/gres.conf.5
+++ b/doc/man/man5/gres.conf.5
@@ -1,4 +1,4 @@
-.TH "gres.conf" "5" "July 2010" "gres.conf 2.2" "Slurm configuration file"
+.TH "gres.conf" "5" "September 2010" "gres.conf 2.2" "Slurm configuration file"
 .SH "NAME"
 gres.conf \- Slurm configuration file for generic resource management.
 
@@ -24,7 +24,8 @@ The overall configuration parameters available include:
 \fBCount\fR
 Number of resources of this type available on this node.
 The default value is set to the number of \fBFile\fR values specified (if any),
-otherwise the default value is one.
+otherwise the default value is one. A suffix of "K", "M" or "G" may be used
+to mulitply the number by 1024, 1048576 or 1073741824 respectively.
 
 .TP
 \fBCPUs\fR
diff --git a/doc/man/man5/slurm.conf.5 b/doc/man/man5/slurm.conf.5
index 2723b1a041b..6937235273b 100644
--- a/doc/man/man5/slurm.conf.5
+++ b/doc/man/man5/slurm.conf.5
@@ -2129,7 +2129,9 @@ Also see \fBGres\fR.
 A comma delimited list of generic resources specifications for a node.
 Each resource specification consists of a name followed by an optional
 colon with a numeric value (default value is one)
-(e.g. "Gres=bandwidth:10000,gpus").
+(e.g. "Gres=bandwidth:10000,gpus:2").
+A suffix of "K", "M" or "G" may be used to mulitply the number by 1024,
+1048576 or 1073741824 respectively (e.g. "Gres=bandwidth:4G,gpus:4")..
 By default a node has no generic resources.
 Also see \fBFeature\fR.
 
diff --git a/src/common/gres.c b/src/common/gres.c
index 12e4dfeaefb..4bbf4b89268 100644
--- a/src/common/gres.c
+++ b/src/common/gres.c
@@ -674,6 +674,8 @@ static int _parse_gres_config(void **dest, slurm_parser_enum_t type,
 			tmp_long *= 1024;
 		else if ((last[0] == 'm') || (last[0] == 'M'))
 			tmp_long *= (1024 * 1024);
+		else if ((last[0] == 'g') || (last[0] == 'G'))
+			tmp_long *= (1024 * 1024 * 1024);
 		else if (last[0] != '\0') {
 			fatal("Invalid gres data for %s, Count=%s", p->name,
 			      tmp_str);
@@ -979,6 +981,8 @@ static uint32_t _get_gres_cnt(char *orig_config, char *gres_name,
 				gres_config_cnt *= 1024;
 			else if ((last_num[0] == 'm') || (last_num[0] == 'M'))
 				gres_config_cnt *= (1024 * 1024);
+			else if ((last_num[0] == 'g') || (last_num[0] == 'G'))
+				gres_config_cnt *= (1024 * 1024 * 1024);
 			break;
 		}
 		tok = strtok_r(NULL, ",", &last_tok);
@@ -1009,6 +1013,10 @@ static void _set_gres_cnt(char *orig_config, char **new_config,
 		if (strcmp(tok, gres_name) &&
 		    strncmp(tok, gres_name_colon, gres_name_colon_len)) {
 			xstrcat(new_configured_res, tok);
+		} else if ((new_cnt % (1024 * 1024 * 1024)) == 0) {
+			new_cnt /= (1024 * 1024 * 1024);
+			xstrfmtcat(new_configured_res, "%s:%uG",
+				   gres_name, new_cnt);
 		} else if ((new_cnt % (1024 * 1024)) == 0) {
 			new_cnt /= (1024 * 1024);
 			xstrfmtcat(new_configured_res, "%s:%uM",
@@ -1902,6 +1910,8 @@ static int _job_config_validate(char *config, uint32_t *gres_cnt,
 			cnt *= 1024;
 		else if ((last_num[0] == 'm') || (last_num[0] == 'M'))
 			cnt *= (1024 * 1024);
+		else if ((last_num[0] == 'g') || (last_num[0] == 'G'))
+			cnt *= (1024 * 1024 * 1024);
 		else
 			return SLURM_ERROR;
 		if (cnt < 0)
-- 
GitLab