Skip to content
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

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

Closed
Vali-98 opened this issue Sep 5, 2024 · 2 comments
Labels
bug-unconfirmed high severity Used to report high severity bugs in llama.cpp (Malfunctioning hinder important workflow)

Comments

@Vali-98
Copy link

Vali-98 commented Sep 5, 2024

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

@Vali-98 Vali-98 added bug-unconfirmed high severity Used to report high severity bugs in llama.cpp (Malfunctioning hinder important workflow) labels Sep 5, 2024
@ngxson
Copy link
Collaborator

ngxson commented Sep 7, 2024

After #9336, the code branch using cpu_set_t will not longer built on android. So I assume that you won't get this error anymore.

@ngxson ngxson closed this as completed Sep 7, 2024
@Vali-98
Copy link
Author

Vali-98 commented Sep 9, 2024

Tested in my pipeline and working. Issue resolved. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-unconfirmed high severity Used to report high severity bugs in llama.cpp (Malfunctioning hinder important workflow)
Projects
None yet
Development

No branches or pull requests

2 participants