Skip to content
Closed
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
Correct syscall name SYS_get_cpu used with old glibc where getcpu() i…
…s missing.

Handle both SYS_get_cpu and SYS_getcpu, even though I am unsure if both ever existed,
and make sure to error out if neither of them are available.

Fixes #1894.
  • Loading branch information
petterreinholdtsen committed Feb 24, 2024
commit 7469011f4f4bd42c5270e919e88ac6eefc06fe67
13 changes: 11 additions & 2 deletions ggml.c
Original file line number Diff line number Diff line change
Expand Up @@ -2084,8 +2084,17 @@ void ggml_numa_init(enum ggml_numa_strategy numa_flag) {
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 28)
getcpu_ret = getcpu(&current_cpu, &g_state.numa.current_node);
#else
// old glibc doesn't have a wrapper for this call. Fall back on direct syscall
getcpu_ret = syscall(SYS_getcpu,&current_cpu,&g_state.numa.current_node);
// old glibc doesn't have a wrapper for this call. Fall back on
// direct syscall
getcpu_ret = syscall(
# if defined(SYS_getcpu)
SYS_getcpu,
# elif defined(SYS_get_cpu)
SYS_get_cpu,
# else
# error "Unable fo find getcpu syscall define"
# endif /* SYS_getcpu */
&current_cpu,&g_state.numa.current_node);
Comment on lines +2087 to +2097
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something like this would be more readable:

Suggested change
// old glibc doesn't have a wrapper for this call. Fall back on
// direct syscall
getcpu_ret = syscall(
# if defined(SYS_getcpu)
SYS_getcpu,
# elif defined(SYS_get_cpu)
SYS_get_cpu,
# else
# error "Unable fo find getcpu syscall define"
# endif /* SYS_getcpu */
&current_cpu,&g_state.numa.current_node);
# if !defined(SYS_getcpu) && defined(SYS_get_cpu)
# define SYS_getcpu SYS_get_cpu
# endif
// old glibc doesn't have a wrapper for this call. Fall back on direct syscall
getcpu_ret = syscall(SYS_getcpu, &current_cpu, &g_state.numa.current_node);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cebtenzzre that looks like an elegant solution.
@petterreinholdtsen are you able to test cebtenzzre's proposed fix and confirm that it works in your case?

#endif

if (g_state.numa.n_nodes < 1 || g_state.numa.total_cpus < 1 || getcpu_ret != 0) {
Expand Down