diff --git a/common/common.cpp b/common/common.cpp index a1387531..c37ef4cc 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -835,6 +835,7 @@ struct llama_init_result llama_init_from_gpt_params(gpt_params & params) { } // profile devices and determine the best setup + const char * dev_name = profiler::device_name(); uint32_t n_cpu_cores = profiler::device_cpu_cores(); uint64_t total_memory = profiler::device_physical_memory(false); uint64_t available_memory = profiler::device_physical_memory(true); @@ -842,6 +843,7 @@ struct llama_init_result llama_init_from_gpt_params(gpt_params & params) { uint64_t available_swap = profiler::device_swap_memory(true); uint64_t disk_read_bw = profiler::get_disk_read_speed(params.model.c_str(), 500); + LOG_INF("Device Name: %s\n", dev_name); LOG_INF("Number of CPU cores: %u\n", n_cpu_cores); LOG_INF("Total Physical Memory: %.2f GB\n", total_memory / (double)(1 << 30)); LOG_INF("Available Physical Memory: %.2f GB\n", available_memory / (double)(1 << 30)); diff --git a/common/profiler.cpp b/common/profiler.cpp index f6b7b4a9..3e842f9f 100644 --- a/common/profiler.cpp +++ b/common/profiler.cpp @@ -21,6 +21,29 @@ namespace profiler { +const char * device_name() { + static char device_name[256]; + +#if defined(_WIN32) || defined(_WIN64) + DWORD size = sizeof(device_name); + if (GetComputerNameA(device_name, &size) == 0) { + strncpy(device_name, "Unknown Windows Device", sizeof(device_name)); + } +#elif defined(__linux__) + if (gethostname(device_name, sizeof(device_name)) != 0) { + strncpy(device_name, "Unknown Linux Device", sizeof(device_name)); + } +#elif defined(__APPLE__) && defined(__MACH__) + if (gethostname(device_name, sizeof(device_name)) != 0) { + strncpy(device_name, "Unknown Mac Device", sizeof(device_name)); + } +#else + strncpy(device_name, "Unknown Device", sizeof(device_name)); +#endif + + return device_name; +} + uint32_t device_cpu_cores() { unsigned int core_count = 1; // default to 1 in case of failure diff --git a/common/profiler.h b/common/profiler.h index 347ebb96..95dfcb09 100644 --- a/common/profiler.h +++ b/common/profiler.h @@ -4,6 +4,7 @@ #include namespace profiler { + const char * device_name(); uint32_t device_cpu_cores(); uint64_t device_physical_memory(bool available = true); uint64_t device_swap_memory(bool available = true);