From 766ec7862b17b262461b365707317e65c2efe215 Mon Sep 17 00:00:00 2001 From: Lizonghang <870644199@qq.com> Date: Tue, 5 Nov 2024 17:22:24 +0400 Subject: [PATCH] test --- Makefile | 8 +++++++- common/common.cpp | 5 +++++ common/profiler.cpp | 7 +++++++ common/profiler.h | 8 ++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 common/profiler.cpp create mode 100644 common/profiler.h diff --git a/Makefile b/Makefile index 4bd59eb5..d7fd072c 100644 --- a/Makefile +++ b/Makefile @@ -945,7 +945,8 @@ OBJ_COMMON = \ common/sampling.o \ common/train.o \ common/build-info.o \ - common/json-schema-to-grammar.o + common/json-schema-to-grammar.o \ + common/profiler.o OBJ_ALL = $(OBJ_GGML) $(OBJ_LLAMA) $(OBJ_COMMON) @@ -1186,6 +1187,11 @@ common/arg.o: \ common/arg.h $(CXX) $(CXXFLAGS) -c $< -o $@ +common/profiler.o: \ + common/profiler.cpp \ + common/profiler.h + $(CXX) $(CXXFLAGS) -c $< -o $@ + common/log.o: \ common/log.cpp \ common/log.h diff --git a/common/common.cpp b/common/common.cpp index e72e07ee..3fe33ff3 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -9,6 +9,7 @@ #include "json.hpp" #include "json-schema-to-grammar.h" #include "llama.h" +#include "profile.h" #include #include @@ -833,6 +834,10 @@ struct llama_init_result llama_init_from_gpt_params(gpt_params & params) { model = llama_load_model_from_file(params.model.c_str(), mparams); } + // profile devices and determine the best setup + uint32_t n_cpu_cores = profiler::get_cpu_core_count(); + LOG_INF("Number of CPU cores on this device: %i\n", n_cpu_cores); + if (model == NULL) { LOG_ERR("%s: failed to load model '%s'\n", __func__, params.model.c_str()); return iparams; diff --git a/common/profiler.cpp b/common/profiler.cpp new file mode 100644 index 00000000..8e4676cb --- /dev/null +++ b/common/profiler.cpp @@ -0,0 +1,7 @@ +#include "profiler.h" + +namespace profiler { +unsigned int get_cpu_core_count() { + return 4; +} +} // namespace profiler \ No newline at end of file diff --git a/common/profiler.h b/common/profiler.h new file mode 100644 index 00000000..b384caf0 --- /dev/null +++ b/common/profiler.h @@ -0,0 +1,8 @@ +#ifndef PROFILER_H +#define PROFILER_H + +namespace profiler { + unsigned int get_cpu_core_count(); +} // namespace profiler + +#endif // PROFILER_H \ No newline at end of file