Skip to content

Get CPU model in ggml_backend_cpu_device_context on FreeBSD #12902

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions ggml/src/ggml-cpu/ggml-cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
#include <sys/sysctl.h>
#endif

#if defined(__FreeBSD__)
#include <sys/types.h>
#include <sys/sysctl.h>
#include <errno.h>
#include <string.h>
#include <iostream>
Comment on lines +29 to +31
Copy link
Member

Choose a reason for hiding this comment

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

Unless necessary for something else in this file, remove these includes.

Suggested change
#include <errno.h>
#include <string.h>
#include <iostream>

#endif

#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#ifndef NOMINMAX
Expand Down Expand Up @@ -285,6 +293,14 @@ struct ggml_backend_cpu_device_context {
}
fclose(f);
}
#elif defined(__FreeBSD__)
char buf[1024];
size_t size = sizeof(buf);
int rc = sysctlbyname("hw.model", buf, &size, nullptr, 0);
if (rc == 0)
description = buf;
else
std::cerr << "error: sysctlbyname(hw.model) failed: " << strerror(errno) << std::endl;
Comment on lines +300 to +303
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (rc == 0)
description = buf;
else
std::cerr << "error: sysctlbyname(hw.model) failed: " << strerror(errno) << std::endl;
if (rc == 0) {
description = buf;
}

#elif defined(_WIN32)
HKEY hKey;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
Expand Down
Loading