Skip to content

Commit 60bce33

Browse files
Merge pull request #176 from igchor/hwloc_valgrind
Fix Valgrind runs
2 parents 8064716 + 03d9be9 commit 60bce33

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

.github/workflows/nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Install apt packages
2323
run: |
2424
sudo apt-get update
25-
sudo apt-get install -y cmake libhwloc-dev libjemalloc-dev libnuma-dev libtbb-dev valgrind
25+
sudo apt-get install -y cmake hwloc libhwloc-dev libjemalloc-dev libnuma-dev libtbb-dev valgrind
2626
2727
- name: Configure CMake
2828
run: >

src/memory_targets/memory_target_numa.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static umf_result_t numa_initialize(void *params, void **memTarget) {
4141

4242
static void numa_finalize(void *memTarget) { free(memTarget); }
4343

44+
// sets maxnode and allocates and initializes mask based on provided memory targets
4445
static umf_result_t
4546
numa_targets_create_nodemask(struct numa_memory_target_t **targets,
4647
size_t numTargets, unsigned long **mask,
@@ -61,13 +62,26 @@ numa_targets_create_nodemask(struct numa_memory_target_t **targets,
6162
}
6263
}
6364

64-
int nrUlongs = hwloc_bitmap_nr_ulongs(bitmap);
65-
if (nrUlongs == -1) {
65+
int lastBit = hwloc_bitmap_last(bitmap);
66+
if (lastBit == -1) {
67+
// no node is set
6668
hwloc_bitmap_free(bitmap);
67-
return UMF_RESULT_ERROR_UNKNOWN;
69+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
6870
}
6971

72+
*maxnode = lastBit + 1;
73+
74+
// Do not use hwloc_bitmap_nr_ulongs due to:
75+
// https://github.com/open-mpi/hwloc/issues/429
76+
unsigned bits_per_long = sizeof(unsigned long) * 8;
77+
int nrUlongs = (lastBit + bits_per_long) / bits_per_long;
78+
7079
unsigned long *nodemask = malloc(sizeof(unsigned long) * nrUlongs);
80+
if (!nodemask) {
81+
hwloc_bitmap_free(bitmap);
82+
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
83+
}
84+
7185
int ret = hwloc_bitmap_to_ulongs(bitmap, nrUlongs, nodemask);
7286
hwloc_bitmap_free(bitmap);
7387

@@ -77,7 +91,6 @@ numa_targets_create_nodemask(struct numa_memory_target_t **targets,
7791
}
7892

7993
*mask = nodemask;
80-
*maxnode = nrUlongs * sizeof(unsigned long) * 8;
8194

8295
return UMF_RESULT_SUCCESS;
8396
}

src/provider/provider_os_memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static umf_result_t nodemask_to_hwloc_nodeset(const unsigned long *nodemask,
111111

112112
unsigned bits_per_mask = sizeof(unsigned long) * 8;
113113
hwloc_bitmap_from_ulongs(
114-
*out_nodeset, (maxnode + bits_per_mask) / bits_per_mask, nodemask);
114+
*out_nodeset, (maxnode + bits_per_mask - 1) / bits_per_mask, nodemask);
115115

116116
return UMF_RESULT_SUCCESS;
117117
}

test/test_valgrind.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,18 @@ esac
4949

5050
FAIL=0
5151

52+
mkdir -p cpuid
53+
54+
echo "Gathering data for hwloc so it can be run under valgrind:"
55+
hwloc-gather-cpuid ./cpuid
56+
5257
echo "Running: \"valgrind $OPTION\" for the following tests:"
5358

5459
for tf in $(ls -1 ./test/umf_test-*); do
5560
[ ! -x $tf ] && continue
5661
echo -n "$tf "
5762
LOG=${tf}.log
58-
valgrind $OPTION $tf >$LOG 2>&1 || echo -n "(valgrind failed) "
63+
HWLOC_CPUID_PATH=./cpuid valgrind $OPTION $tf >$LOG 2>&1 || echo -n "(valgrind failed) "
5964
if grep -q -e "ERROR SUMMARY: 0 errors from 0 contexts" $LOG; then
6065
echo "- OK"
6166
rm $LOG

0 commit comments

Comments
 (0)