mirror of
https://github.com/Lizonghang/prima.cpp.git
synced 2025-09-06 14:29:05 +00:00
check env path before calling fio to ensure we can find it
This commit is contained in:
parent
2d649c808d
commit
36f353e374
2 changed files with 42 additions and 2 deletions
|
@ -1486,7 +1486,7 @@ struct llama_init_result llama_init_from_gpt_params(gpt_params & params) {
|
|||
|
||||
if (auto_schedule) {
|
||||
// get device profile
|
||||
LOG_INF("Start profiling this device, this may take some seconds ...\n");
|
||||
LOG_INF("\nstart profiling this device, this may take some seconds ...\n");
|
||||
dev_info.rank = params.rank;
|
||||
llama_profile_device(&dev_info, model, ml, params.gpu_mem, params.n_predict, params.n_ctx, params.cpuparams.n_threads, params.flash_attn);
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
#include "ggml.h"
|
||||
#include "ggml-backend.h"
|
||||
#include "llama.h"
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <windows.h>
|
||||
#elif defined(__linux__)
|
||||
#include <unistd.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
@ -828,6 +828,44 @@ static size_t get_default_readahead_size() {
|
|||
#endif
|
||||
}
|
||||
|
||||
static std::vector<std::string> split(const std::string & str, char delimiter) {
|
||||
std::vector<std::string> tokens;
|
||||
std::stringstream ss(str);
|
||||
std::string token;
|
||||
while (std::getline(ss, token, delimiter)) {
|
||||
tokens.push_back(token);
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
static bool path_exist_in_env(const std::string & path, const std::string & env_path) {
|
||||
auto paths = split(env_path, ':');
|
||||
return std::find(paths.begin(), paths.end(), path) != paths.end();
|
||||
}
|
||||
|
||||
static bool path_exist_in_fs(const std::string & path) {
|
||||
struct stat info;
|
||||
return (stat(path.c_str(), &info) == 0 && (info.st_mode & S_IFDIR));
|
||||
}
|
||||
|
||||
static void check_env_path() {
|
||||
const char * cur_env_path = std::getenv("PATH");
|
||||
std::string update_env_path = cur_env_path ? cur_env_path : "";
|
||||
std::vector<std::string> paths_to_check = {"/opt/homebrew/bin", "/usr/local/bin"};
|
||||
|
||||
for (const auto & path : paths_to_check) {
|
||||
if (!path_exist_in_env(path, update_env_path) && path_exist_in_fs(path)) {
|
||||
if (!update_env_path.empty() && update_env_path.back() != ':') {
|
||||
update_env_path += ':';
|
||||
}
|
||||
update_env_path += path;
|
||||
LOG_INF("add missing path: %s, current env path: %s\n", path.c_str(), update_env_path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
setenv("PATH", update_env_path.c_str(), 1);
|
||||
}
|
||||
|
||||
static void external_fio_impl(float * read_bw, float * write_bw, bool op_rand, int n_threads) {
|
||||
const char * test_file = "fio_test";
|
||||
const char * fio_conf_template = R"(
|
||||
|
@ -890,6 +928,8 @@ numjobs=%d
|
|||
const char * output_file = "fio_output.log";
|
||||
const char * conf_file = "config.fio";
|
||||
|
||||
check_env_path(); // ensure the fio bin file can be found
|
||||
|
||||
int num_try = 0;
|
||||
int ret;
|
||||
while (num_try < 2) {
|
||||
|
|
Loading…
Add table
Reference in a new issue