Skip to content

Fix Valgrind runs #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install apt packages
run: |
sudo apt-get update
sudo apt-get install -y cmake libhwloc-dev libjemalloc-dev libnuma-dev libtbb-dev valgrind
sudo apt-get install -y cmake hwloc libhwloc-dev libjemalloc-dev libnuma-dev libtbb-dev valgrind

- name: Configure CMake
run: >
Expand Down
21 changes: 17 additions & 4 deletions src/memory_targets/memory_target_numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static umf_result_t numa_initialize(void *params, void **memTarget) {

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

// sets maxnode and allocates and initializes mask based on provided memory targets
static umf_result_t
numa_targets_create_nodemask(struct numa_memory_target_t **targets,
size_t numTargets, unsigned long **mask,
Expand All @@ -61,13 +62,26 @@ numa_targets_create_nodemask(struct numa_memory_target_t **targets,
}
}

int nrUlongs = hwloc_bitmap_nr_ulongs(bitmap);
if (nrUlongs == -1) {
int lastBit = hwloc_bitmap_last(bitmap);
if (lastBit == -1) {
// no node is set
hwloc_bitmap_free(bitmap);
return UMF_RESULT_ERROR_UNKNOWN;
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

*maxnode = lastBit + 1;

// Do not use hwloc_bitmap_nr_ulongs due to:
// https://github.com/open-mpi/hwloc/issues/429
unsigned bits_per_long = sizeof(unsigned long) * 8;
int nrUlongs = (lastBit + bits_per_long) / bits_per_long;

unsigned long *nodemask = malloc(sizeof(unsigned long) * nrUlongs);
if (!nodemask) {
hwloc_bitmap_free(bitmap);
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}

int ret = hwloc_bitmap_to_ulongs(bitmap, nrUlongs, nodemask);
hwloc_bitmap_free(bitmap);

Expand All @@ -77,7 +91,6 @@ numa_targets_create_nodemask(struct numa_memory_target_t **targets,
}

*mask = nodemask;
*maxnode = nrUlongs * sizeof(unsigned long) * 8;

return UMF_RESULT_SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion src/provider/provider_os_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static umf_result_t nodemask_to_hwloc_nodeset(const unsigned long *nodemask,

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

return UMF_RESULT_SUCCESS;
}
Expand Down
7 changes: 6 additions & 1 deletion test/test_valgrind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,18 @@ esac

FAIL=0

mkdir -p cpuid

echo "Gathering data for hwloc so it can be run under valgrind:"
hwloc-gather-cpuid ./cpuid

echo "Running: \"valgrind $OPTION\" for the following tests:"

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