ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ggma Namespace Reference

Data Structures

class  Context
 
struct  GGMAConfig
 
struct  KVCache
 
struct  ModelConfig
 
class  SentencePieceTokenizer
 
class  Tokenizer
 
class  TokenizerFactory
 

Enumerations

enum class  KVCacheDataType { FLOAT32 , UINT8 }
 

Functions

template<typename T >
void load_config_field (const Json::Value &root, const std::string &field_name, T &target, bool is_optional=false)
 
template<>
void load_config_field< bool > (const Json::Value &root, const std::string &field_name, bool &target, bool is_optional)
 
template<>
void load_config_field< std::optional< int > > (const Json::Value &root, const std::string &field_name, std::optional< int > &target, bool is_optional)
 
bool validate_model_config (const ModelConfig &config)
 
std::string to_string (const ModelConfig &config)
 
nnfw_sessioncreate_and_prepare_session (const std::string &model_path)
 
uint64_t num_elems (const nnfw_tensorinfo *tensor_info)
 
uint64_t bufsize_for (const nnfw_tensorinfo *ti)
 
template void Context::decode_impl< false, std::vector< uint8_t > > (ggma_token token_id, std::vector< uint8_t > &output)
 
template void Context::decode_impl< true, std::vector< float > > (ggma_token token_id, std::vector< float > &output)
 
const char * to_string (KVCacheDataType type)
 
KVCacheDataType from_string (const std::string &type_str)
 
bool is_supported_type (KVCacheDataType type)
 

Enumeration Type Documentation

◆ KVCacheDataType

enum class ggma::KVCacheDataType
strong
Enumerator
FLOAT32 
UINT8 

Definition at line 36 of file KVCache.h.

37{
38 FLOAT32,
39 UINT8
40};

Function Documentation

◆ bufsize_for()

uint64_t ggma::bufsize_for ( const nnfw_tensorinfo ti)

Definition at line 63 of file Context.cc.

64{
65 static int elmsize[] = {
66 sizeof(float), /* NNFW_TYPE_TENSOR_FLOAT32 */
67 sizeof(int), /* NNFW_TYPE_TENSOR_INT32 */
68 sizeof(uint8_t), /* NNFW_TYPE_TENSOR_QUANT8_ASYMM */
69 sizeof(bool), /* NNFW_TYPE_TENSOR_BOOL = 3 */
70 sizeof(uint8_t), /* NNFW_TYPE_TENSOR_UINT8 = 4 */
71 sizeof(int64_t), /* NNFW_TYPE_TENSOR_INT64 = 5 */
72 sizeof(int8_t), /* NNFW_TYPE_TENSOR_QUANT8_ASYMM_SIGNED = 6 */
73 sizeof(int16_t), /* NNFW_TYPE_TENSOR_QUANT16_SYMM_SIGNED = 7 */
74 };
75 return elmsize[ti->dtype] * num_elems(ti);
76}
uint64_t num_elems(const nnfw_tensorinfo *ti)
Definition minimal.cc:21
NNFW_TYPE dtype

References nnfw_tensorinfo::dtype, and num_elems().

Referenced by ggma::Context::prefill(), and ggma::Context::unemb().

◆ Context::decode_impl< false, std::vector< uint8_t > >()

template void ggma::Context::decode_impl< false, std::vector< uint8_t > > ( ggma_token  token_id,
std::vector< uint8_t > &  output 
)

◆ Context::decode_impl< true, std::vector< float > >()

template void ggma::Context::decode_impl< true, std::vector< float > > ( ggma_token  token_id,
std::vector< float > &  output 
)

◆ create_and_prepare_session()

nnfw_session * ggma::create_and_prepare_session ( const std::string &  model_path)

Definition at line 45 of file Context.cc.

46{
47 nnfw_session *session = nullptr;
49 NNFW_ENSURE_STATUS(nnfw_load_model_from_file(session, model_path.c_str()));
51 return session;
52}
#define NNFW_ENSURE_STATUS(a)
Definition Context.cc:35
NNFW_STATUS nnfw_prepare(nnfw_session *session)
Prepare session to be ready for inference.
Definition APIImpl.cc:78
NNFW_STATUS nnfw_create_session(nnfw_session **session)
Create a new session instance.
NNFW_STATUS nnfw_load_model_from_file(nnfw_session *session, const char *package_file_path)
Load model from nnpackage file or directory.

References nnfw_create_session(), NNFW_ENSURE_STATUS, nnfw_load_model_from_file(), and nnfw_prepare().

Referenced by ggma::Context::prefill(), and ggma::Context::unemb().

◆ from_string()

KVCacheDataType ggma::from_string ( const std::string &  type_str)

Definition at line 42 of file KVCache.cc.

43{
44 if (type_str == "FLOAT32" || type_str == "float32")
45 {
46 return KVCacheDataType::FLOAT32;
47 }
48 else if (type_str == "UINT8" || type_str == "uint8")
49 {
50 return KVCacheDataType::UINT8;
51 }
52 throw std::runtime_error("Unsupported KV cache data type: " + type_str);
53}

References FLOAT32, and UINT8.

◆ is_supported_type()

bool ggma::is_supported_type ( KVCacheDataType  type)

Definition at line 56 of file KVCache.cc.

57{
58 switch (type)
59 {
60 case KVCacheDataType::FLOAT32:
61 case KVCacheDataType::UINT8:
62 return true;
63 default:
64 return false;
65 }
66}
int32_t type

References FLOAT32, type, and UINT8.

◆ load_config_field()

template<typename T >
void ggma::load_config_field ( const Json::Value &  root,
const std::string &  field_name,
T &  target,
bool  is_optional = false 
)

Definition at line 28 of file Config.cc.

30{
31 if (root.isMember(field_name))
32 target = root[field_name].asInt();
33 else if (!is_optional)
34 throw std::runtime_error(field_name + " not found in config.json");
35}

Referenced by ggma::ModelConfig::load_from_json().

◆ load_config_field< bool >()

template<>
void ggma::load_config_field< bool > ( const Json::Value &  root,
const std::string &  field_name,
bool &  target,
bool  is_optional 
)

Definition at line 39 of file Config.cc.

41{
42 if (root.isMember(field_name))
43 target = root[field_name].asBool();
44 else if (!is_optional)
45 throw std::runtime_error(field_name + " not found in config.json");
46}

◆ load_config_field< std::optional< int > >()

template<>
void ggma::load_config_field< std::optional< int > > ( const Json::Value &  root,
const std::string &  field_name,
std::optional< int > &  target,
bool  is_optional 
)

Definition at line 50 of file Config.cc.

52{
53 if (root.isMember(field_name))
54 target = root[field_name].asInt();
55}

◆ num_elems()

uint64_t ggma::num_elems ( const nnfw_tensorinfo tensor_info)

Definition at line 55 of file Context.cc.

56{
57 uint64_t n = 1;
58 for (int32_t i = 0; i < tensor_info->rank; ++i)
59 n *= tensor_info->dims[i];
60 return n;
61}
int32_t dims[NNFW_MAX_RANK]

References nnfw_tensorinfo::dims, and nnfw_tensorinfo::rank.

Referenced by bufsize_for(), and ggma::Context::unemb().

◆ to_string() [1/2]

std::string ggma::to_string ( const ModelConfig config)

Definition at line 144 of file Config.cc.

144{ return config.to_string(); }

◆ to_string() [2/2]

const char * ggma::to_string ( KVCacheDataType  type)

Definition at line 28 of file KVCache.cc.

29{
30 switch (type)
31 {
32 case KVCacheDataType::FLOAT32:
33 return "FLOAT32";
34 case KVCacheDataType::UINT8:
35 return "UINT8";
36 default:
37 return "UNKNOWN";
38 }
39}

References FLOAT32, type, and UINT8.

◆ validate_model_config()

bool ggma::validate_model_config ( const ModelConfig config)

Definition at line 142 of file Config.cc.

142{ return config.is_valid(); }