mirror of
https://github.com/Lizonghang/prima.cpp.git
synced 2025-09-09 14:14:59 +00:00
add os detect
This commit is contained in:
parent
d9beb030ee
commit
fa31ca8e35
3 changed files with 46 additions and 0 deletions
|
@ -71,6 +71,27 @@ const char * device_name() {
|
||||||
return device_name;
|
return device_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char * device_os() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
return "Windows";
|
||||||
|
#elif __linux__
|
||||||
|
std::ifstream versionFile("/proc/version");
|
||||||
|
if (versionFile.is_open()) {
|
||||||
|
std::string line;
|
||||||
|
std::getline(versionFile, line);
|
||||||
|
versionFile.close();
|
||||||
|
if (line.find("Android") != std::string::npos) {
|
||||||
|
return "Android";
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "Linux";
|
||||||
|
#elif __APPLE__ || __MACH__
|
||||||
|
return "macOS";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t device_cpu_cores() {
|
uint32_t device_cpu_cores() {
|
||||||
unsigned int core_count = 1; // default to 1 in case of failure
|
unsigned int core_count = 1; // default to 1 in case of failure
|
||||||
|
|
||||||
|
@ -1527,6 +1548,12 @@ void device_print_props(struct device_info * dev_info_set, int n, struct llama_m
|
||||||
}
|
}
|
||||||
LOG_INF("\n");
|
LOG_INF("\n");
|
||||||
|
|
||||||
|
LOG_INF("| Device OS ");
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
LOG_INF("| %-10.10s ", dev_info_set[i].device_os);
|
||||||
|
}
|
||||||
|
LOG_INF("\n");
|
||||||
|
|
||||||
LOG_INF("| CPU Name ");
|
LOG_INF("| CPU Name ");
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
LOG_INF("| %-10.10s ", dev_info_set[i].cpu_props.name);
|
LOG_INF("| %-10.10s ", dev_info_set[i].cpu_props.name);
|
||||||
|
@ -1960,6 +1987,7 @@ void device_print_props(struct device_info * dev_info_set, int n, struct llama_m
|
||||||
size_t serialize(const struct device_info * dev_info, char ** buffer) {
|
size_t serialize(const struct device_info * dev_info, char ** buffer) {
|
||||||
// calculate total size for serialized buffer
|
// calculate total size for serialized buffer
|
||||||
size_t device_name_len = strlen(dev_info->device_name) + 1;
|
size_t device_name_len = strlen(dev_info->device_name) + 1;
|
||||||
|
size_t device_os_len = strlen(dev_info->device_os) + 1;
|
||||||
size_t cpu_name_len = strlen(dev_info->cpu_props.name) + 1;
|
size_t cpu_name_len = strlen(dev_info->cpu_props.name) + 1;
|
||||||
size_t cpu_description_len = strlen(dev_info->cpu_props.description) + 1;
|
size_t cpu_description_len = strlen(dev_info->cpu_props.description) + 1;
|
||||||
size_t gpu_name_len = strlen(dev_info->gpu_props.name) + 1;
|
size_t gpu_name_len = strlen(dev_info->gpu_props.name) + 1;
|
||||||
|
@ -1968,6 +1996,7 @@ size_t serialize(const struct device_info * dev_info, char ** buffer) {
|
||||||
size_t total_size = sizeof(uint32_t)
|
size_t total_size = sizeof(uint32_t)
|
||||||
+ sizeof(size_t) * 5 // for lengths of strings
|
+ sizeof(size_t) * 5 // for lengths of strings
|
||||||
+ device_name_len
|
+ device_name_len
|
||||||
|
+ device_os_len
|
||||||
+ cpu_name_len
|
+ cpu_name_len
|
||||||
+ cpu_description_len
|
+ cpu_description_len
|
||||||
+ gpu_name_len
|
+ gpu_name_len
|
||||||
|
@ -1995,6 +2024,11 @@ size_t serialize(const struct device_info * dev_info, char ** buffer) {
|
||||||
memcpy(ptr, dev_info->device_name, device_name_len);
|
memcpy(ptr, dev_info->device_name, device_name_len);
|
||||||
ptr += device_name_len;
|
ptr += device_name_len;
|
||||||
|
|
||||||
|
memcpy(ptr, &device_os_len, sizeof(size_t));
|
||||||
|
ptr += sizeof(size_t);
|
||||||
|
memcpy(ptr, dev_info->device_os, device_os_len);
|
||||||
|
ptr += device_os_len;
|
||||||
|
|
||||||
memcpy(ptr, &cpu_name_len, sizeof(size_t));
|
memcpy(ptr, &cpu_name_len, sizeof(size_t));
|
||||||
ptr += sizeof(size_t);
|
ptr += sizeof(size_t);
|
||||||
memcpy(ptr, dev_info->cpu_props.name, cpu_name_len);
|
memcpy(ptr, dev_info->cpu_props.name, cpu_name_len);
|
||||||
|
@ -2118,6 +2152,14 @@ void deserialize(const char * buffer, struct device_info * dev_info) {
|
||||||
memcpy(const_cast<void*>(static_cast<const void*>(dev_info->device_name)), ptr, device_name_len);
|
memcpy(const_cast<void*>(static_cast<const void*>(dev_info->device_name)), ptr, device_name_len);
|
||||||
ptr += device_name_len;
|
ptr += device_name_len;
|
||||||
|
|
||||||
|
// device_os
|
||||||
|
size_t device_os_len;
|
||||||
|
memcpy(&device_os_len, ptr, sizeof(size_t));
|
||||||
|
ptr += sizeof(size_t);
|
||||||
|
dev_info->device_os = (char *)malloc(device_os_len);
|
||||||
|
memcpy(const_cast<void*>(static_cast<const void*>(dev_info->device_os)), ptr, device_os_len);
|
||||||
|
ptr += device_os_len;
|
||||||
|
|
||||||
// cpu_props.name
|
// cpu_props.name
|
||||||
size_t cpu_name_len;
|
size_t cpu_name_len;
|
||||||
memcpy(&cpu_name_len, ptr, sizeof(size_t));
|
memcpy(&cpu_name_len, ptr, sizeof(size_t));
|
||||||
|
|
|
@ -216,6 +216,7 @@ struct disk_props {
|
||||||
struct device_info {
|
struct device_info {
|
||||||
uint32_t rank;
|
uint32_t rank;
|
||||||
const char * device_name;
|
const char * device_name;
|
||||||
|
const char * device_os;
|
||||||
struct disk_props disk;
|
struct disk_props disk;
|
||||||
struct cpu_props cpu_props;
|
struct cpu_props cpu_props;
|
||||||
struct memory_info memory;
|
struct memory_info memory;
|
||||||
|
@ -228,6 +229,7 @@ struct device_info {
|
||||||
device_info() :
|
device_info() :
|
||||||
rank(0),
|
rank(0),
|
||||||
device_name(""),
|
device_name(""),
|
||||||
|
device_os(""),
|
||||||
disk(),
|
disk(),
|
||||||
cpu_props(),
|
cpu_props(),
|
||||||
memory(),
|
memory(),
|
||||||
|
@ -251,6 +253,7 @@ enum profiler_layer_type {
|
||||||
};
|
};
|
||||||
|
|
||||||
const char * device_name(void);
|
const char * device_name(void);
|
||||||
|
const char * device_os(void);
|
||||||
|
|
||||||
uint32_t device_cpu_cores (void);
|
uint32_t device_cpu_cores (void);
|
||||||
float device_cpu_flops (struct llama_model * model, enum ggml_type src0t, enum ggml_type src1t, int n_threads);
|
float device_cpu_flops (struct llama_model * model, enum ggml_type src0t, enum ggml_type src1t, int n_threads);
|
||||||
|
|
|
@ -3579,6 +3579,7 @@ void llama_profile_device(
|
||||||
int n_threads,
|
int n_threads,
|
||||||
bool flash_attn) {
|
bool flash_attn) {
|
||||||
dev_info->device_name = device_name();
|
dev_info->device_name = device_name();
|
||||||
|
dev_info->device_os = device_os();
|
||||||
dev_info->cpu_props.cores = device_cpu_cores();
|
dev_info->cpu_props.cores = device_cpu_cores();
|
||||||
|
|
||||||
dev_info->memory.total_physical = round(device_physical_memory(false) / (double)(1 << 30) * 100) / 100;
|
dev_info->memory.total_physical = round(device_physical_memory(false) / (double)(1 << 30) * 100) / 100;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue