diff --git a/src/include/AutoModel/all_models.hpp b/src/include/AutoModel/all_models.hpp index 9506de53..f021f6a1 100644 --- a/src/include/AutoModel/all_models.hpp +++ b/src/include/AutoModel/all_models.hpp @@ -63,7 +63,7 @@ inline std::pair> get_auto_model(const s if (available_models.is_model_supported(model_tag) == false) { - header_print("Error", "Model tag '" << model_tag << "' is not supported. Please check the model list."); + header_print_r("ERROR", "Model tag '" << model_tag << "' is not supported. Please check the model list."); return std::make_pair("llama3.2:1b", std::make_unique(npu_device_inst)); } @@ -116,7 +116,7 @@ inline std::pair> get_auto_model(const s case SupportedModelFamily::error_whiper: case SupportedModelFamily::error_embedding: default: - header_print("Error", "Unsupported model family or non-llm: " << model_info["details"]["family"]); + header_print_r("ERROR", "Unsupported model family or non-llm: " << model_info["details"]["family"]); auto_chat_engine = std::make_unique(npu_device_inst); new_model_tag = "llama3.2:1b"; } diff --git a/src/include/model_list.hpp b/src/include/model_list.hpp index 62760f6b..f99ddb74 100644 --- a/src/include/model_list.hpp +++ b/src/include/model_list.hpp @@ -91,8 +91,8 @@ class model_list { if (!model_found) { if (last_error_tag != new_tag) { last_error_tag = new_tag; - header_print("ERROR", "Model not found: " + model_size + " in subset " + model_type); - header_print("ERROR", "Using default model: llama3.2-1B"); + header_print_r("ERROR", "Model not found: " + model_size + " in subset " + model_type); + header_print_r("ERROR", "Using default model: llama3.2-1B"); } return std::make_pair("llama3.2:1b", this->config["models"]["llama3.2"]["1b"]); } @@ -100,7 +100,7 @@ class model_list { else{ if (last_error_tag != new_tag) { last_error_tag = new_tag; - header_print("ERROR", "Model subset not found: " << model_type << "; using default model: llama3.2-1B"); + header_print_r("ERROR", "Model subset not found: " << model_type << "; using default model: llama3.2-1B"); } return std::make_pair("llama3.2:1b", this->config["models"]["llama3.2"]["1b"]); } diff --git a/src/include/npu_utils/npu_instr_utils.hpp b/src/include/npu_utils/npu_instr_utils.hpp index bdaba3bc..ee971da6 100644 --- a/src/include/npu_utils/npu_instr_utils.hpp +++ b/src/include/npu_utils/npu_instr_utils.hpp @@ -478,22 +478,22 @@ class npu_sequence{ constexpr int wrap_bits = 10; if(size[3] > (1<< wrap_bits)){ - header_print("ERROR", ": step_3 out ouf range"); + header_print_r("ERROR", ": step_3 out ouf range"); } if(stride[3] > (1<< step_bits)){ - header_print("ERROR", ": stride_3 out of range"); + header_print_r("ERROR", ": stride_3 out of range"); } if(size[2] > (1<< wrap_bits)){ - header_print("ERROR", ": step_2 out ouf range"); + header_print_r("ERROR", ": step_2 out ouf range"); } if(stride[2] > (1<< step_bits)){ - header_print("ERROR", ": stride_2 out of range"); + header_print_r("ERROR", ": stride_2 out of range"); } if(size[1] > (1<< wrap_bits)){ - header_print("ERROR", ": step_1 out ouf range"); + header_print_r("ERROR", ": step_1 out ouf range"); } if(stride[1] > (1<< step_bits)){ - header_print("ERROR", ": stride_1 out of range"); + header_print_r("ERROR", ": stride_1 out of range"); } // inverse of human's order cmd->dim0_size = size[3]; diff --git a/src/include/npu_utils/npu_utils.hpp b/src/include/npu_utils/npu_utils.hpp index 6912c42c..4163db37 100644 --- a/src/include/npu_utils/npu_utils.hpp +++ b/src/include/npu_utils/npu_utils.hpp @@ -94,7 +94,7 @@ class npu_app { NULL, 0, (void**)elf_buf, NULL, 0, "", "", NULL, 0); assert(elf_buf_size > 0); if (elf_buf_size == 0){ - header_print("error", "Failed to get elf from ctrl_seq"); + header_print_r("ERROR", "Failed to get elf from ctrl_seq"); exit(1); } return elf_buf_size; @@ -210,7 +210,7 @@ class npu_app { uint32_t elf_buf_size = this->_gen_elf(&elf_buf, data); std::ofstream fout(elf_name, std::ios::binary); if (fout.is_open() == false) { - header_print("error", "Failed to open file: " << elf_name); + header_print_r("ERROR", "Failed to open file: " << elf_name); exit(1); } fout.write((char*)elf_buf, elf_buf_size); diff --git a/src/include/utils/debug_utils.hpp b/src/include/utils/debug_utils.hpp index a02ea56a..76d32adb 100644 --- a/src/include/utils/debug_utils.hpp +++ b/src/include/utils/debug_utils.hpp @@ -121,7 +121,7 @@ do { \ std::ostringstream oss; \ oss << msg; \ - std::cout << "\033[31m[" << header << "] " << oss.str() << "\033[0m" << std::endl; \ + std::cerr << "\033[31m[" << header << "] " << oss.str() << "\033[0m" << std::endl; \ } while (0) diff --git a/src/src/benchmarking.hpp b/src/src/benchmarking.hpp index 1d770e9d..67a5bf56 100644 --- a/src/src/benchmarking.hpp +++ b/src/src/benchmarking.hpp @@ -133,7 +133,7 @@ inline void write_bench_csv(const BenchmarkResults_t& results, const std::string std::ofstream out(filename, std::ios::out | std::ios::trunc); if (!out.is_open()) { - header_print("ERROR", "Failed to open output file: " + filename); + header_print_r("ERROR", "Failed to open output file: " + filename); return; } @@ -260,7 +260,7 @@ BenchmarkResults_t run_benchmarks(std::string model_tag, std::string bench_confi else { std::ifstream input_file(bench_config_file); if (!input_file.is_open()) { - header_print("ERROR", "Failed to open input file: " + bench_config_file); + header_print_r("ERROR", "Failed to open input file: " + bench_config_file); return results; } bench_config = nlohmann::json::parse(input_file); @@ -270,7 +270,7 @@ BenchmarkResults_t run_benchmarks(std::string model_tag, std::string bench_confi xrt::device npu_device_inst = xrt::device(0); std::unique_ptr auto_chat_engine; if (!availble_models.is_model_supported(model_tag)) { - header_print("ERROR", "Model not found: " << model_tag << "; Please check with `flm list` and try again."); + header_print_r("ERROR", "Model not found: " << model_tag << "; Please check with `flm list` and try again."); return results; } auto [new_tag, model_info] = availble_models.get_model_info(model_tag); diff --git a/src/src/main.cpp b/src/src/main.cpp index 0b06e17c..78defb85 100644 --- a/src/src/main.cpp +++ b/src/src/main.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -242,11 +243,11 @@ static bool sanity_check_npu_stack(bool quiet) { sscanf(u_name.release, "%d.%d", &major, &minor); bool kernel_ok = (major > 6) || (major == 6 && minor >= 14); if (!kernel_ok) { - header_print("ERROR", "Kernel version incompatible with this version of FLM. Please update your kernel!"); + header_print_r("ERROR", "Kernel version incompatible with this version of FLM. Please update your kernel!"); return false; } if (!quiet) { - header_print("Linux", "Kernel Version: " << u_name.release); + header_print("Linux", "Kernel: " << u_name.release); } // Check firmware version of all AMD devices @@ -276,7 +277,7 @@ static bool sanity_check_npu_stack(bool quiet) { // ENOTTY means it's not an AMD device, just ignore it. if (errno != ENOTTY) { if (!quiet) { - std::cout << "Error code: " << ret << " on " << dev_name << std::endl; + header_print_r("ERROR", "Error code: " << ret << " on " << dev_name); perror("Failed to get firmware version"); } } @@ -286,22 +287,41 @@ static bool sanity_check_npu_stack(bool quiet) { amd_device_found = true; if (!quiet) { - header_print("Linux", "Found AMD NPU at " + dev_name); - header_print("Linux", "NPU FW Version: " << query_fw_version.major << "." << query_fw_version.minor << "." << query_fw_version.patch << "." << query_fw_version.build); + header_print_g("Linux", "NPU: " + dev_name); + header_print_g("Linux", "NPU FW Version: " << query_fw_version.major << "." << query_fw_version.minor << "." << query_fw_version.patch << "." << query_fw_version.build); } bool fw_ok = (query_fw_version.major > 1 || (query_fw_version.major == 1 && query_fw_version.minor >= 1)); if (!fw_ok) { all_fw_ok = false; - header_print("ERROR", "NPU firmware version on " + dev_name + " is incompatible. Please update NPU firmware!"); + header_print_r("ERROR", "NPU firmware version on " + dev_name + " is incompatible. Please update NPU firmware!"); } } if (!amd_device_found && !quiet) { - header_print("ERROR", "No AMD NPU device found."); + header_print_r("ERROR", "No NPU device found."); } - return amd_device_found && kernel_ok && all_fw_ok; + // Check memlock limit + bool memlock_ok = true; + struct rlimit rl; + if (getrlimit(RLIMIT_MEMLOCK, &rl) == 0) { + if (rl.rlim_cur != RLIM_INFINITY && rl.rlim_cur < 100 * 1024 * 1024) { + header_print_r("ERROR", "Memlock limit is too low (" << (rl.rlim_cur / 1024 / 1024) << "MB). Please raise the limit or set to infinity."); + memlock_ok = false; + } else if (!quiet) { + if (rl.rlim_cur == RLIM_INFINITY) { + header_print_g("Linux", "Memlock Limit: infinity"); + } else { + header_print("Linux", "Memlock Limit: " << (rl.rlim_cur / 1024 / 1024) << " MB"); + } + } + } else { + if (!quiet) + perror("Failed to get memlock limit"); + } + + return amd_device_found && kernel_ok && all_fw_ok && memlock_ok; #else return true; #endif