From c9a9fa6d74a80a8c8f4c5e898dfb7fd188f2ab06 Mon Sep 17 00:00:00 2001 From: Hyeongseok Oh Date: Thu, 19 Sep 2024 10:32:21 +0900 Subject: [PATCH] [onert] Initialize ggml context in CPU ExternalContext (#14011) This commit updates CPU backend ExternalContext to initialize GGML context to prepare GGML support. ONE-DCO-1.0-Signed-off-by: Hyeongseok Oh --- runtime/onert/backend/cpu/CMakeLists.txt | 2 ++ runtime/onert/backend/cpu/ExternalContext.h | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/runtime/onert/backend/cpu/CMakeLists.txt b/runtime/onert/backend/cpu/CMakeLists.txt index 12777a2173d..92cdf3c18d1 100644 --- a/runtime/onert/backend/cpu/CMakeLists.txt +++ b/runtime/onert/backend/cpu/CMakeLists.txt @@ -12,6 +12,8 @@ target_link_libraries(${LIB_ONERT_BACKEND_CPU} PRIVATE nnfw_coverage) target_link_libraries(${LIB_ONERT_BACKEND_CPU} PRIVATE ruy) target_link_libraries(${LIB_ONERT_BACKEND_CPU} INTERFACE ruy_instrumentation) target_link_libraries(${LIB_ONERT_BACKEND_CPU} PRIVATE ndarray) +# Set public: ExternalContext is used in train backend +target_link_libraries(${LIB_ONERT_BACKEND_CPU} PUBLIC ggml) set_target_properties(${LIB_ONERT_BACKEND_CPU} PROPERTIES OUTPUT_NAME backend_cpu diff --git a/runtime/onert/backend/cpu/ExternalContext.h b/runtime/onert/backend/cpu/ExternalContext.h index 8c1f4ccf16c..9c7e9368bc2 100644 --- a/runtime/onert/backend/cpu/ExternalContext.h +++ b/runtime/onert/backend/cpu/ExternalContext.h @@ -19,6 +19,7 @@ #include #include +#include #include @@ -47,10 +48,18 @@ class ExternalContext _ruy_context->set_max_num_threads(target_num_threads); } + void initGgmlContext() + { + if (_ggml_context == nullptr) + _ggml_context = std::unique_ptr( + ggml_init({.mem_size = 0, .mem_buffer = nullptr, .no_alloc = true}), &ggml_free); + } + ruy::Context *ruy_context() const { return _ruy_context.get(); } private: const std::unique_ptr _ruy_context; + std::unique_ptr _ggml_context{nullptr, &ggml_free}; }; } // namespace cpu