ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ggma_context.cc File Reference
#include "ggma_context.h"
#include "Context.h"
#include <iostream>

Go to the source code of this file.

Functions

GGMA_STATUS ggma_create_context (ggma_context **context, const char *package_path)
 Creates a context from a package path.
 
GGMA_STATUS ggma_free_context (ggma_context *context)
 Closes a GGMA context and releases its resources.
 

Function Documentation

◆ ggma_create_context()

GGMA_STATUS ggma_create_context ( ggma_context **  context,
const char *  package_path 
)

Creates a context from a package path.

This function initializes a context for inference from the specified package path. Once the context is no longer needed, it must be destroyed by calling ggma_free_context.

Parameters
[out]contextA pointer to the variable that will receive the new context handle.
[in]package_pathThe path to the GGMA package directory.
Returns
GGMA_STATUS_NO_ERROR on success, or an appropriate error code on failure.

Definition at line 23 of file ggma_context.cc.

24{
25 if (context == nullptr)
27 try
28 {
29 *context = reinterpret_cast<ggma_context *>(new ggma::Context(package_path));
30 }
31 catch (const std::bad_alloc &e)
32 {
33 std::cerr << "Error during context creation" << std::endl;
34 *context = nullptr;
36 }
37 catch (const std::exception &e)
38 {
39 std::cerr << "Error during context initialization : " << e.what() << std::endl;
40 *context = nullptr;
41 return GGMA_STATUS_ERROR;
42 }
44}
struct ggma_context ggma_context
Opaque handle to a GGMA inference context.
@ GGMA_STATUS_NO_ERROR
Definition ggma_types.h:37
@ GGMA_STATUS_UNEXPECTED_NULL
Definition ggma_types.h:44
@ GGMA_STATUS_ERROR
Definition ggma_types.h:42
@ GGMA_STATUS_OUT_OF_MEMORY
Definition ggma_types.h:46

References GGMA_STATUS_ERROR, GGMA_STATUS_NO_ERROR, GGMA_STATUS_OUT_OF_MEMORY, and GGMA_STATUS_UNEXPECTED_NULL.

◆ ggma_free_context()

GGMA_STATUS ggma_free_context ( ggma_context context)

Closes a GGMA context and releases its resources.

This function deallocates all resources associated with the context, including the GGMA package it was created with. After this function returns, the context handle is invalid and must not be used.

Parameters
[in]contextThe context to close.
Returns
GGMA_STATUS_NO_ERROR on success, or an appropriate error code on failure.

Definition at line 46 of file ggma_context.cc.

47{
48 delete reinterpret_cast<ggma::Context *>(context);
50}

References GGMA_STATUS_NO_ERROR.