Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion packaging/nnfw.spec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Source2001: EXTERNALS_FOR_ODC.tar.gz
%{!?odc_build: %define odc_build 1}
%endif
%{!?test_build: %define test_build 0}
%{!?ggma_build: %define ggma_build 1}
%{!?extra_option: %define extra_option %{nil}}
# Define nproc on gbs build option if you want to set number of build threads manually (ex. CI/CD infra)
%define build_jobs %{?!nproc:%{?_smp_mflags}%{?!_smp_mflags:-j4}}%{?nproc:-j%nproc}
Expand Down Expand Up @@ -89,6 +90,23 @@ Summary: NNFW On-Device Compilation Package
NNFW package for on-device compilation
%endif # odc_build

%if %{ggma_build} == 1
%package ggma
Summary: GGMA generative AI framework

%description ggma
GGMA package for on-device generative AI framework

%files ggma
%manifest %{name}.manifest
%defattr(-,root,root,-)
%ifarch arm armv7l armv7hl aarch64 x86_64 %ix86 riscv64
%{_libdir}/ggma/libggma_api.so
%{_includedir}/ggma/*
%{_libdir}/pkgconfig/ggma.pc
%endif
%endif # ggma_build

%if %{test_build} == 1
%package test
Summary: NNFW Test
Expand Down Expand Up @@ -136,11 +154,17 @@ If you want to use test package, you should install runtime package which is bui
%define option_config -DASAN_BUILD=ON
%endif # asan

# Set option for GGMA build
%define option_ggma -DBUILD_GGMA_API=OFF
%if %{ggma_build} == 1
%define option_ggma -DBUILD_GGMA_API=ON
%endif # ggma_build

# CMAKE_INSTALL_PREFIX is used for config files
# Actual install path is set by --prefix option in cmake install command
%define build_options -DCMAKE_BUILD_TYPE=%{build_type} -DTARGET_ARCH=%{target_arch} -DTARGET_OS=tizen \\\
-DEXTERNALS_BUILD_THREAD=%{nproc} -DBUILD_MINIMAL_SAMPLE=OFF -DNNFW_OVERLAY_DIR=$(pwd)/%{overlay_path} \\\
-DCMAKE_INSTALL_PREFIX=%{_prefix} %{option_test} %{option_config} %{extra_option}
-DCMAKE_INSTALL_PREFIX=%{_prefix} %{option_test} %{option_config} %{option_ggma} %{extra_option}

%prep
%setup -q
Expand Down
1 change: 1 addition & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,6 @@ add_subdirectory(compute)
add_subdirectory(contrib)
add_subdirectory(libs)
add_subdirectory(onert)
add_subdirectory(ggma)
add_subdirectory(tests)
add_subdirectory(tools)
43 changes: 43 additions & 0 deletions runtime/ggma/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
if (NOT BUILD_GGMA_API)
return()
endif()

file(GLOB_RECURSE API_SRC "src/*.cc")

set(GGMA_DEV ggma-dev)
add_library(${GGMA_DEV} SHARED ${API_SRC})

# Public headers to publish
set(GGMA_API_HEADERS include/ggma_api.h include/ggma_macro.h include/ggma_types.h
include/ggma_context.h include/ggma_generate.h)

# GGMA install directory (same as ONERT_INSTALL_APIDIR)
set(GGMA_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR}/ggma)
set(GGMA_INSTALL_APIDIR ${CMAKE_INSTALL_LIBDIR}/ggma)

target_link_libraries(${GGMA_DEV} PRIVATE jsoncpp ${LIB_PTHREAD})
target_link_libraries(${GGMA_DEV} PRIVATE nnfw-dev)

# NOTE Below line is added to remove warning for android build
# It will be removed after android build uses gold linker
if (ANDROID)
target_link_libraries(${GGMA_DEV} INTERFACE log)
endif (ANDROID)

target_include_directories(${GGMA_DEV} PUBLIC include)

# GGMA RPATH configuration: find ggma libraries
set(GGMA_RPATH_API "$ORIGIN:$ORIGIN/..")

set_target_properties(${GGMA_DEV} PROPERTIES
PUBLIC_HEADER "${GGMA_API_HEADERS}"
OUTPUT_NAME ggma_api
INSTALL_RPATH ${GGMA_RPATH_API})

install(TARGETS ${GGMA_DEV}
LIBRARY DESTINATION ${GGMA_INSTALL_APIDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ggma)

# Install pkg-config file for GGMA API
configure_file(ggma.pc.in ggma.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ggma.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
10 changes: 10 additions & 0 deletions runtime/ggma/ggma.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
prefix=@CMAKE_INSTALL_PREFIX@
libdir=${prefix}/@GGMA_INSTALL_APIDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
version=@CMAKE_PROJECT_VERSION@

Name: ggma
Description: GGMA API
Version: ${version}
Libs: -L${libdir} -lggma
Cflags: -I${includedir}/ggma
36 changes: 36 additions & 0 deletions runtime/ggma/include/ggma_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file ggma_api.h
* @brief This file defines the Generative Model API (GGMA) - main include header.
*/
#ifndef __GGMA_GGMA_API_H__
#define __GGMA_GGMA_API_H__

/* Include all GGMA API headers */
#include "ggma_context.h"
#include "ggma_generate.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

#endif // __GGMA_GGMA_API_H__
67 changes: 67 additions & 0 deletions runtime/ggma/include/ggma_context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file ggma_context.h
* @brief This file defines the GGMA context management API.
*/
#ifndef __GGMA_GGMA_CONTEXT_H__
#define __GGMA_GGMA_CONTEXT_H__

#include "ggma_types.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Opaque handle to a GGMA inference context.
*
* A GGMA context represents the environment for inference.
* It includes model, computation graph, KV caches, and other resources for token generation.
*/
typedef struct ggma_context ggma_context;

/**
* @brief 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
* {@link ggma_free_context}.
*
* @param[out] context A pointer to the variable that will receive the new context handle.
* @param[in] package_path The path to the GGMA package directory.
* @return @c GGMA_STATUS_NO_ERROR on success, or an appropriate error code on failure.
*/
GGMA_STATUS ggma_create_context(ggma_context **context, const char *package_path);

/**
* @brief 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.
*
* @param[in] context The context to close.
* @return @c GGMA_STATUS_NO_ERROR on success, or an appropriate error code on failure.
*/
GGMA_STATUS ggma_free_context(ggma_context *context);

#ifdef __cplusplus
}
#endif

#endif // __GGMA_GGMA_CONTEXT_H__
56 changes: 56 additions & 0 deletions runtime/ggma/include/ggma_generate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file ggma_generate.h
* @brief This file defines the GGMA text generation API.
*/
#ifndef __GGMA_GENERATE_H__
#define __GGMA_GENERATE_H__

#include "ggma_types.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Forward declaration */
struct ggma_context;

/**
* @brief Generates a sequence of tokens based on the provided prompt tokens.
*
* This function performs the core inference step, taking an initial sequence of
* prompt tokens and generating new tokens autoregressively.
*
* @param[in] context The GGMA context to use for generation.
* @param[inout] tokens An array of input prompt tokens. The generated tokens will
* be placed in this buffer
* @param[in] n_tokens The number of tokens in the input @p tokens array. This also
* often specifies the maximum number of tokens to generate.
* @param[in] n_tokens_max The maximum number of tokens that the @p tokens buffer can hold.
* @param[out] n_tokens_out A pointer to a variable that will receive the number of
* element in the @p tokens after generation
* @return @c GGMA_STATUS_NO_ERROR on success, or an appropriate error code on failure.
*/
GGMA_STATUS ggma_generate(struct ggma_context *context, ggma_token *tokens, size_t n_tokens,
size_t n_tokens_max, size_t *n_tokens_out);

#ifdef __cplusplus
}
#endif

#endif // __GGMA_GENERATE_H__
45 changes: 45 additions & 0 deletions runtime/ggma/include/ggma_macro.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <cstdlib>

/**
* @file ggma_macro.h
* @brief Common macros for GGMA error handling and utilities
*/
#ifndef __GGMA_GGMA_MACRO_H__
#define __GGMA_GGMA_MACRO_H__

#define GGMA_ENSURE(a) \
do \
{ \
if ((a) != GGMA_STATUS_NO_ERROR) \
{ \
exit(-1); \
} \
} while (0)

#define GGMA_UNUSED(x) (void)(x)

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

#endif // __GGMA_GGMA_MACRO_H__
60 changes: 60 additions & 0 deletions runtime/ggma/include/ggma_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file ggma_types.h
* @brief This file defines the core types and status codes for GGMA API.
*/
#ifndef __GGMA_GGMA_TYPES_H__
#define __GGMA_GGMA_TYPES_H__

#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Enumeration of status codes returned by GGMA API functions.
*/
typedef enum
{
/** The operation completed successfully. */
GGMA_STATUS_NO_ERROR = 0,
/**
* A general error occurred.
* This code is typically used when no more specific error code is applicable.
*/
GGMA_STATUS_ERROR = 1,
/** Unexpected null argument is given. */
GGMA_STATUS_UNEXPECTED_NULL = 2,
/** The system ran out of memory. */
GGMA_STATUS_OUT_OF_MEMORY = 4,
/** The called API function is deprecated and should no longer be used. */
GGMA_STATUS_DEPRECATED_API = 6,
} GGMA_STATUS;

/* Forward declarations */
typedef struct ggma_context ggma_context;
typedef int32_t ggma_token;
typedef struct ggma_tokenizer ggma_tokenizer;

#ifdef __cplusplus
}
#endif

#endif // __GGMA_GGMA_TYPES_H__
Loading