Skip to content

Commit 0bbbad5

Browse files
committed
synthetic: accept memory/cache size as GiB/KiB and handle GB/kB correctly
Refs #519 Signed-off-by: Brice Goglin <[email protected]>
1 parent 123ad5e commit 0bbbad5

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

doc/hwloc.doxy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,11 +2537,11 @@ space-separated attributes. For instance:
25372537
<li>
25382538
<tt>L2iCache:2(size=32kB)</tt> specifies 2 children
25392539
of 32kB level-2 instruction caches.
2540-
The size may be specified in bytes (without any unit suffix) or as TB, GB, MB or kB.
2540+
The size may be specified in bytes (without any unit suffix) or as kB, KiB, MB, MiB, etc.
25412541
</li>
25422542
<li>
25432543
<tt>NUMANode:3(memory=16MB)</tt> specifies 3 NUMA nodes with 16MB each.
2544-
The size may be specified in bytes (without any unit suffix) or as TB, GB, MB or kB.
2544+
The size may be specified in bytes (without any unit suffix) or as GB, GiB, TB, TiB, etc.
25452545
</li>
25462546
<li>
25472547
<tt>PU:2(indexes=0,2,1,3)</tt> specifies 2 PU children and the

hwloc/topology-synthetic.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright © 2009 CNRS
3-
* Copyright © 2009-2020 Inria. All rights reserved.
3+
* Copyright © 2009-2022 Inria. All rights reserved.
44
* Copyright © 2009-2010 Université Bordeaux
55
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
66
* See COPYING in top-level directory.
@@ -323,17 +323,29 @@ hwloc_synthetic_parse_memory_attr(const char *attr, const char **endp)
323323
hwloc_uint64_t size;
324324
size = strtoull(attr, (char **) &endptr, 0);
325325
if (!hwloc_strncasecmp(endptr, "TB", 2)) {
326-
size <<= 40;
326+
size *= 1000ULL*1000ULL*1000ULL*1000ULL;
327327
endptr += 2;
328+
} else if (!hwloc_strncasecmp(endptr, "TiB", 3)) {
329+
size <<= 40;
330+
endptr += 3;
328331
} else if (!hwloc_strncasecmp(endptr, "GB", 2)) {
329-
size <<= 30;
332+
size *= 1000ULL*1000ULL*1000ULL;
330333
endptr += 2;
334+
} else if (!hwloc_strncasecmp(endptr, "GiB", 3)) {
335+
size <<= 30;
336+
endptr += 3;
331337
} else if (!hwloc_strncasecmp(endptr, "MB", 2)) {
332-
size <<= 20;
338+
size *= 1000ULL*1000ULL;
333339
endptr += 2;
340+
} else if (!hwloc_strncasecmp(endptr, "MiB", 3)) {
341+
size <<= 20;
342+
endptr += 3;
334343
} else if (!hwloc_strncasecmp(endptr, "kB", 2)) {
335-
size <<= 10;
344+
size *= 1000ULL;
336345
endptr += 2;
346+
} else if (!hwloc_strncasecmp(endptr, "kiB", 3)) {
347+
size <<= 10;
348+
endptr += 3;
337349
}
338350
*endp = endptr;
339351
return size;
@@ -802,15 +814,15 @@ hwloc_backend_synthetic_init(struct hwloc_synthetic_backend_data_s *data,
802814
} else if (hwloc__obj_type_is_cache(type)) {
803815
if (!curlevel->attr.memorysize) {
804816
if (1 == curlevel->attr.depth)
805-
/* 32Kb in L1 */
817+
/* 32KiB in L1 */
806818
curlevel->attr.memorysize = 32*1024;
807819
else
808-
/* *4 at each level, starting from 1MB for L2, unified */
820+
/* *4 at each level, starting from 1MiB for L2, unified */
809821
curlevel->attr.memorysize = 256ULL*1024 << (2*curlevel->attr.depth);
810822
}
811823

812824
} else if (type == HWLOC_OBJ_NUMANODE && !curlevel->attr.memorysize) {
813-
/* 1GB in memory nodes. */
825+
/* 1GiB in memory nodes. */
814826
curlevel->attr.memorysize = 1024*1024*1024;
815827
}
816828

0 commit comments

Comments
 (0)