mirror of
https://github.com/Lizonghang/prima.cpp.git
synced 2025-09-09 15:34:33 +00:00
add disk read speed test
This commit is contained in:
parent
9cd66f2145
commit
9eed6b14bf
3 changed files with 72 additions and 5 deletions
|
@ -838,9 +838,11 @@ struct llama_init_result llama_init_from_gpt_params(gpt_params & params) {
|
||||||
uint32_t n_cpu_cores = profiler::device_cpu_cores();
|
uint32_t n_cpu_cores = profiler::device_cpu_cores();
|
||||||
uint64_t total_memory = profiler::device_physical_memory(false);
|
uint64_t total_memory = profiler::device_physical_memory(false);
|
||||||
uint64_t available_memory = profiler::device_physical_memory(true);
|
uint64_t available_memory = profiler::device_physical_memory(true);
|
||||||
|
uint64_t disk_read_bw = profiler::get_disk_read_speed(params.model.c_str(), 500);
|
||||||
LOG_INF("Number of CPU cores: %u\n", n_cpu_cores);
|
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("Total Physical Memory: %.2f GB\n", total_memory / (double)(1 << 30));
|
||||||
LOG_INF("Available Physical Memory: %.2f GB\n", available_memory / (double)(1 << 30));
|
LOG_INF("Available Physical Memory: %.2f GB\n", available_memory / (double)(1 << 30));
|
||||||
|
LOG_INF("Disk Read Bandwidth: %.2f GB/s\n", disk_read_bw / (double)(1 << 30));
|
||||||
|
|
||||||
if (model == NULL) {
|
if (model == NULL) {
|
||||||
LOG_ERR("%s: failed to load model '%s'\n", __func__, params.model.c_str());
|
LOG_ERR("%s: failed to load model '%s'\n", __func__, params.model.c_str());
|
||||||
|
|
|
@ -12,7 +12,12 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace profiler {
|
namespace profiler {
|
||||||
|
|
||||||
|
@ -62,10 +67,29 @@ uint64_t device_physical_memory(bool available) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
struct sysinfo info;
|
if (available) {
|
||||||
if (sysinfo(&info) == 0) {
|
// read available memory from /proc/meminfo
|
||||||
memory = available ? info.freeram : info.totalram;
|
std::ifstream meminfo("/proc/meminfo");
|
||||||
memory *= info.mem_unit;
|
std::string line;
|
||||||
|
if (meminfo.is_open()) {
|
||||||
|
while (std::getline(meminfo, line)) {
|
||||||
|
if (line.find("MemAvailable:") == 0) {
|
||||||
|
std::istringstream iss(line);
|
||||||
|
std::string key;
|
||||||
|
uint64_t kb;
|
||||||
|
iss >> key >> kb;
|
||||||
|
memory = kb * 1024;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
meminfo.close();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// get total memory using sysinfo
|
||||||
|
struct sysinfo info;
|
||||||
|
if (sysinfo(&info) == 0) {
|
||||||
|
memory = info.totalram * info.mem_unit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__APPLE__) && defined(__MACH__)
|
#elif defined(__APPLE__) && defined(__MACH__)
|
||||||
|
@ -88,4 +112,42 @@ uint64_t device_physical_memory(bool available) {
|
||||||
|
|
||||||
return memory;
|
return memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t get_disk_read_speed(const char * test_file, size_t buffer_size_mb) {
|
||||||
|
uint64_t speed = 0;
|
||||||
|
size_t buffer_size = buffer_size_mb * 1024 * 1024; // buffer size in bytes
|
||||||
|
|
||||||
|
try {
|
||||||
|
// open a file for reading
|
||||||
|
std::ifstream file(test_file, std::ios::binary | std::ios::in);
|
||||||
|
if (!file) {
|
||||||
|
LOG_ERR("Unable to open the file at path: %s\n", test_file);
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prepare buffer for reading
|
||||||
|
std::vector<char> buffer(buffer_size);
|
||||||
|
|
||||||
|
auto start_time = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
// read file into buffer
|
||||||
|
file.read(buffer.data(), buffer.size());
|
||||||
|
if (!file) {
|
||||||
|
LOG_ERR("Failed to read enough data from the test file\n");
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto end_time = std::chrono::high_resolution_clock::now();
|
||||||
|
std::chrono::duration<double> elapsed_time = end_time - start_time;
|
||||||
|
|
||||||
|
// Calculate speed in bytes per second
|
||||||
|
if (elapsed_time.count() > 0) {
|
||||||
|
speed = static_cast<uint64_t>(buffer.size() / elapsed_time.count());
|
||||||
|
}
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
LOG_ERR("Exception while calculating disk read speed: %s\n", e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
} // namespace profiler
|
} // namespace profiler
|
|
@ -1,9 +1,12 @@
|
||||||
#ifndef PROFILER_H
|
#ifndef PROFILER_H
|
||||||
#define PROFILER_H
|
#define PROFILER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace profiler {
|
namespace profiler {
|
||||||
uint32_t device_cpu_cores();
|
uint32_t device_cpu_cores();
|
||||||
uint64_t device_physical_memory(bool available = true);
|
uint64_t device_physical_memory(bool available = true);
|
||||||
|
uint64_t get_disk_read_speed(const char * test_file, size_t buffer_size_mb = 500);
|
||||||
} // namespace profiler
|
} // namespace profiler
|
||||||
|
|
||||||
#endif // PROFILER_H
|
#endif // PROFILER_H
|
Loading…
Add table
Add a link
Reference in a new issue