Skip to content

Commit

Permalink
[onert] Initialize ggml context in CPU ExternalContext (Samsung#14011)
Browse files Browse the repository at this point in the history
This commit updates CPU backend ExternalContext to initialize GGML context to prepare GGML support.

ONE-DCO-1.0-Signed-off-by: Hyeongseok Oh <[email protected]>
  • Loading branch information
hseok-oh authored Sep 19, 2024
1 parent 4773ee9 commit c9a9fa6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions runtime/onert/backend/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions runtime/onert/backend/cpu/ExternalContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <util/ConfigSource.h>
#include <ruy/context.h>
#include <ggml.h>

#include <memory>

Expand Down Expand Up @@ -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_context, decltype(&ggml_free)>(
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> _ruy_context;
std::unique_ptr<ggml_context, decltype(&ggml_free)> _ggml_context{nullptr, &ggml_free};
};

} // namespace cpu
Expand Down

0 comments on commit c9a9fa6

Please sign in to comment.