Skip to content

Bug: cpu_set_t is undefined in specific Android Archs, making compilation impossible #9324

@Vali-98

Description

@Vali-98

What happened?

Changes to thread affinity cause Android builds to use:

static bool lm_ggml_thread_apply_affinity(const bool * mask) {
    cpu_set_t cpuset;
    int err;

    CPU_ZERO(&cpuset);

    for (uint32_t i = 0; i < LM_GGML_MAX_N_THREADS; i++) {
        if (mask[i]) {
            LM_GGML_PRINT_DEBUG("Thread %lx: adding %d to cpuset\n", pthread_self(), i);
            CPU_SET(i, &cpuset);
        }
    }
    ...

However, cpu_set_t, CPU_SET and CPU_ZERO does not necessarily exist in all Android NDK versions, causing specific pipelines to fail.

A simple fix would be to add the following definitions:

#ifdef __ANDROID__
#define CPU_SETSIZE 1024
#define __NCPUBITS  (8 * sizeof (unsigned long))
typedef struct
{
   unsigned long __bits[CPU_SETSIZE / __NCPUBITS];
} cpu_set_t;

#define CPU_SET(cpu, cpusetp) \
  ((cpusetp)->__bits[(cpu)/__NCPUBITS] |= (1UL << ((cpu) % __NCPUBITS)))
#define CPU_ZERO(cpusetp) \
  memset((cpusetp), 0, sizeof(cpu_set_t))
#endif

However, this solution seems ineligant. I'm not an in-depth android developer so I'm not sure if there is a more poignant solution.

Name and Version

Custom pipeline for android arm64-v8a

What operating system are you seeing the problem on?

Windows

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug-unconfirmedhigh severityUsed to report high severity bugs in llama.cpp (Malfunctioning hinder important workflow)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions