* @param[out] model The NNTrainer model handle from the given description.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
* @retval #ML_ERROR_CANNOT_ASSIGN_ADDRESS Cannot assign object.
*/
* @param[out] model The NNTrainer model handle from the given description.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
*/
int ml_train_model_construct_with_conf(const char *model_conf,
* @param[in] ... hyperparmeters for compiling the model
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
*/
int ml_train_model_compile(ml_train_model_h model, ...);
* @param[in] ... Hyperparmeters for train model.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
*/
int ml_train_model_run(ml_train_model_h model, ...);
* @param[in] model The NNTrainer model handle from the given description.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
*/
int ml_train_model_destroy(ml_train_model_h model);
* and exploit @a summary if possible.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
*/
int ml_train_model_get_summary(ml_train_model_h model,
* @param[in] layer The NNTrainer layer handle.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
*/
int ml_train_model_add_layer(ml_train_model_h model, ml_train_layer_h layer);
* @param[in] optimizer The NNTrainer optimizer handle.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
*/
int ml_train_model_set_optimizer(ml_train_model_h model,
* @param[in] dataset The NNTrainer dataset handle.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
*/
int ml_train_model_set_dataset(ml_train_model_h model,
* @param[in] type The NNTrainer layer type
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
* @retval #ML_ERROR_CANNOT_ASSIGN_ADDRESS Cannot assign object.
*/
* @param[in] layer The NNTrainer layer handle.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
*/
int ml_train_layer_destroy(ml_train_layer_h layer);
* @param[in] ... Property values with NULL for termination.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
*
* Here is an example of the usage of this function:
* @param[in] type The NNTrainer optimizer type.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
* @retval #ML_ERROR_CANNOT_ASSIGN_ADDRESS Cannot assign object.
*/
* @param[in] optimizer The NNTrainer optimizer handle.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
*/
int ml_train_optimizer_destroy(ml_train_optimizer_h optimizer);
* @param[in] ... Property values with NULL for termination.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
*/
int ml_train_optimizer_set_property(ml_train_optimizer_h optimizer, ...);
* @param[in] test_cb The dataset generator for testing. Can be null.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
* @retval #ML_ERROR_CANNOT_ASSIGN_ADDRESS Cannot assign object.
*/
* @param[in] test_file The dataset file for testing. Can be null.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
* @retval #ML_ERROR_CANNOT_ASSIGN_ADDRESS Cannot assign object.
*/
* @param[in] dataset The NNTrainer dataset handle.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
*/
int ml_train_dataset_destroy(ml_train_dataset_h dataset);
* @param[in] ... Property values with NULL for termination.
* @return @c 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
*/
int ml_train_dataset_set_property(ml_train_dataset_h dataset, ...);
#define ML_NNTRAINER_MAGIC 0x777F888F
+/* Tizen ML feature */
+#if defined(__TIZEN__)
+
+typedef enum {
+ NOT_CHECKED_YET = -1,
+ NOT_SUPPORTED = 0,
+ SUPPORTED = 1
+} feature_state_t;
+
+#if defined(__FEATURE_CHECK_SUPPORT__)
+#define check_feature_state() \
+ do { \
+ int feature_ret = ml_tizen_get_feature_enabled(); \
+ if (ML_ERROR_NONE != feature_ret) \
+ return feature_ret; \
+ } while (0);
+
+#define set_feature_state(...) ml_tizen_set_feature_state(__VA_ARGS__)
+#else /* __FEATURE_CHECK_SUPPORT__ */
+#define check_feature_state()
+#define set_feature_state(...)
+#endif /* __FEATURE_CHECK_SUPPORT__ */
+
+#else /* __TIZEN__ */
+#define check_feature_state()
+#define set_feature_state(...)
+#endif /* __TIZEN__ */
+
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
const char *input_layer_names[],
const char *output_layer_names[]);
+#if defined(__TIZEN__)
+/**
+ * @brief Checks whether machine_learning.training feature is enabled or not.
+ */
+int ml_tizen_get_feature_enabled(void);
+
+/**
+ * @brief Set the feature status of machine_learning.training.
+ * This is only used for Unit test.
+ */
+void ml_tizen_set_feature_state(feature_state_t state);
+#endif /* __TIZEN__ */
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
capi_src += join_paths(meson.current_source_dir(), 'src','nntrainer.cpp')
capi_src += join_paths(meson.current_source_dir(), 'src','nntrainer_util.cpp')
+if get_option('enable-tizen') and get_option('enable-tizen-feature-check')
+ capi_src += join_paths(meson.current_source_dir(), 'src','nntrainer-capi-tizen-feature-check.cpp')
+endif
+
capi_headers = []
capi_headers += join_paths(meson.current_source_dir(), 'include', 'nntrainer.h')
capi_headers += join_paths(meson.current_source_dir(), '..', 'nntrainer-api-common.h')
nntrainer_dep
]
+if get_option('enable-tizen')
+ message('CAPI is in Tizen mode')
+
+ tizen_deps = [
+ dependency('capi-base-common'),
+ dependency('capi-system-info'),
+ dependency('dlog')
+ ]
+
+ capi_deps += tizen_deps
+endif
+
shared_library('capi-nntrainer',
capi_src,
dependencies: capi_deps,
configuration: nntrainer_conf
)
-install_headers( capi_headers,
+install_headers(capi_headers,
subdir: 'nntrainer'
)
--- /dev/null
+// SPDX-License-Identifier: Apache-2.0-only
+/**
+ * Copyright (C) 2020 Parichay Kapoor <pk.kapoor@samsung.com>
+ *
+ * @file nnstreamer-capi-tizen-feature-check.cpp
+ * @date 7 August 2020
+ * @brief NNTrainer/C-API Tizen dependent functions.
+ * @see https://github.com/nnstreamer/nntrainer
+ * @author MyungJoo Ham <myungjoo.ham@samsung.com>
+ * @author Parichay Kapoor <pk.kapoor@samsung.com>
+ * @bug No known bugs except for NYI items
+ */
+
+#if !defined(__TIZEN__) || !defined(__FEATURE_CHECK_SUPPORT__)
+#error "This file can be included only in Tizen."
+#endif
+
+#include <pthread.h>
+#include <system_info.h>
+
+#include <nntrainer_internal.h>
+
+/**
+ * @brief Tizen ML feature.
+ */
+#define ML_TRAIN_FEATURE_PATH "tizen.org/feature/machine_learning.training"
+
+/**
+ * @brief Internal struct to control tizen feature support
+ * (machine_learning.training). -1: Not checked yet, 0: Not supported, 1:
+ * Supported
+ */
+typedef struct _feature_info_s {
+ pthread_mutex_t mutex;
+ feature_state_t feature_state;
+
+ _feature_info_s() : feature_state(NOT_CHECKED_YET) {
+ pthread_mutex_init(&mutex, NULL);
+ }
+
+ ~_feature_info_s() { pthread_mutex_destroy(&mutex); }
+} feature_info_s;
+
+static feature_info_s feature_info;
+
+/**
+ * @brief Set the feature status of machine_learning.training.
+ */
+void ml_tizen_set_feature_state(feature_state_t state) {
+ pthread_mutex_lock(&feature_info.mutex);
+
+ /**
+ * Update feature status
+ * -1: Not checked yet, 0: Not supported, 1: Supported
+ */
+ feature_info.feature_state = state;
+
+ pthread_mutex_unlock(&feature_info.mutex);
+}
+
+/**
+ * @brief Checks whether machine_learning.training feature is enabled or not.
+ */
+int ml_tizen_get_feature_enabled(void) {
+ int ret;
+ int feature_enabled;
+
+ pthread_mutex_lock(&feature_info.mutex);
+ feature_enabled = feature_info.feature_state;
+ pthread_mutex_unlock(&feature_info.mutex);
+
+ if (NOT_SUPPORTED == feature_enabled) {
+ ml_loge("machine_learning.training NOT supported");
+ return ML_ERROR_NOT_SUPPORTED;
+ } else if (NOT_CHECKED_YET == feature_enabled) {
+ bool ml_train_supported = false;
+ ret =
+ system_info_get_platform_bool(ML_TRAIN_FEATURE_PATH, &ml_train_supported);
+ if (0 == ret) {
+ if (false == ml_train_supported) {
+ ml_loge("machine_learning.training NOT supported");
+ ml_tizen_set_feature_state(NOT_SUPPORTED);
+ return ML_ERROR_NOT_SUPPORTED;
+ }
+
+ ml_tizen_set_feature_state(SUPPORTED);
+ } else {
+ switch (ret) {
+ case SYSTEM_INFO_ERROR_INVALID_PARAMETER:
+ ml_loge("failed to get feature value because feature key is not vaild");
+ ret = ML_ERROR_NOT_SUPPORTED;
+ break;
+
+ case SYSTEM_INFO_ERROR_IO_ERROR:
+ ml_loge("failed to get feature value because of input/output error");
+ ret = ML_ERROR_NOT_SUPPORTED;
+ break;
+
+ case SYSTEM_INFO_ERROR_PERMISSION_DENIED:
+ ml_loge("failed to get feature value because of permission denied");
+ ret = ML_ERROR_PERMISSION_DENIED;
+ break;
+
+ default:
+ ml_loge("failed to get feature value because of unknown error");
+ ret = ML_ERROR_NOT_SUPPORTED;
+ break;
+ }
+ return ret;
+ }
+ }
+
+ return ML_ERROR_NONE;
+}
int ml_train_model_construct(ml_train_model_h *model) {
int status = ML_ERROR_NONE;
+
+ check_feature_state();
+
returnable f = [&]() { return nn_object(model); };
status = nntrainer_exception_boundary(f);
returnable f;
std::shared_ptr<nntrainer::NeuralNetwork> NN;
+ check_feature_state();
+
ML_TRAIN_VERIFY_VALID_HANDLE(model);
std::vector<std::string> arg_list;
const char *data;
std::shared_ptr<nntrainer::NeuralNetwork> NN;
+ check_feature_state();
+
ML_TRAIN_VERIFY_VALID_HANDLE(model);
std::vector<std::string> arg_list;
int status = ML_ERROR_NONE;
ml_train_model *nnmodel;
+ check_feature_state();
+
{
ML_TRAIN_GET_VALID_MODEL_LOCKED_RESET(nnmodel, model);
ML_TRAIN_ADOPT_LOCK(nnmodel, model_lock);
int ml_train_model_get_summary(ml_train_model_h model,
ml_train_summary_type_e verbosity,
char **summary) {
+ int status = ML_ERROR_NONE;
+ std::stringstream ss;
+
+ check_feature_state();
+
if (summary == nullptr) {
ml_loge("summary pointer is null");
return ML_ERROR_INVALID_PARAMETER;
}
- int status = ML_ERROR_NONE;
- std::stringstream ss;
-
status = ml_train_model_get_summary_util(model, verbosity, ss);
if (status != ML_ERROR_NONE) {
ml_loge("failed make a summary: %d", status);
ml_train_model *nnmodel;
ml_train_layer *nnlayer;
+ check_feature_state();
+
ML_TRAIN_GET_VALID_MODEL_LOCKED(nnmodel, model);
ML_TRAIN_ADOPT_LOCK(nnmodel, model_lock);
ML_TRAIN_GET_VALID_LAYER_LOCKED(nnlayer, layer);
ml_train_model *nnmodel;
ml_train_optimizer *nnopt;
+ check_feature_state();
+
ML_TRAIN_GET_VALID_MODEL_LOCKED(nnmodel, model);
ML_TRAIN_ADOPT_LOCK(nnmodel, model_lock);
ML_TRAIN_GET_VALID_OPT_LOCKED(nnopt, optimizer);
ml_train_model *nnmodel;
ml_train_dataset *nndataset;
+ check_feature_state();
+
ML_TRAIN_GET_VALID_MODEL_LOCKED(nnmodel, model);
ML_TRAIN_ADOPT_LOCK(nnmodel, model_lock);
ML_TRAIN_GET_VALID_DATASET_LOCKED(nndataset, dataset);
int status = ML_ERROR_NONE;
ml_train_model *nnmodel;
+ check_feature_state();
+
ML_TRAIN_GET_VALID_MODEL_LOCKED(nnmodel, model);
ML_TRAIN_ADOPT_LOCK(nnmodel, model_lock);
int ml_train_layer_create(ml_train_layer_h *layer, ml_train_layer_type_e type) {
int status = ML_ERROR_NONE;
returnable f;
- ml_train_layer *nnlayer = new ml_train_layer;
+ ml_train_layer *nnlayer;
+
+ check_feature_state();
+
+ nnlayer = new ml_train_layer;
nnlayer->magic = ML_NNTRAINER_MAGIC;
try {
int status = ML_ERROR_NONE;
ml_train_layer *nnlayer;
+ check_feature_state();
+
{
ML_TRAIN_GET_VALID_LAYER_LOCKED_RESET(nnlayer, layer);
ML_TRAIN_ADOPT_LOCK(nnlayer, layer_lock);
const char *data;
std::shared_ptr<nntrainer::Layer> NL;
+ check_feature_state();
+
ML_TRAIN_VERIFY_VALID_HANDLE(layer);
std::vector<std::string> arg_list;
ml_train_optimizer_type_e type) {
int status = ML_ERROR_NONE;
+ check_feature_state();
+
ml_train_optimizer *nnopt = new ml_train_optimizer;
nnopt->magic = ML_NNTRAINER_MAGIC;
nnopt->optimizer = std::make_shared<nntrainer::Optimizer>();
int status = ML_ERROR_NONE;
ml_train_optimizer *nnopt;
+ check_feature_state();
+
{
ML_TRAIN_GET_VALID_OPT_LOCKED_RESET(nnopt, optimizer);
ML_TRAIN_ADOPT_LOCK(nnopt, optimizer_lock);
const char *data;
std::shared_ptr<nntrainer::Optimizer> opt;
+ check_feature_state();
+
ML_TRAIN_VERIFY_VALID_HANDLE(optimizer);
std::vector<std::string> arg_list;
ml_train_datagen_cb test_cb) {
int status = ML_ERROR_NONE;
+ check_feature_state();
+
std::shared_ptr<nntrainer::DataBufferFromCallback> data_buffer =
std::make_shared<nntrainer::DataBufferFromCallback>();
const char *test_file) {
int status = ML_ERROR_NONE;
+ check_feature_state();
+
std::shared_ptr<nntrainer::DataBufferFromDataFile> data_buffer =
std::make_shared<nntrainer::DataBufferFromDataFile>();
const char *data;
std::shared_ptr<nntrainer::DataBuffer> data_buffer;
+ check_feature_state();
+
ML_TRAIN_VERIFY_VALID_HANDLE(dataset);
std::vector<std::string> arg_list;
int status = ML_ERROR_NONE;
ml_train_dataset *nndataset;
+ check_feature_state();
+
{
ML_TRAIN_GET_VALID_DATASET_LOCKED_RESET(nndataset, dataset);
ML_TRAIN_ADOPT_LOCK(nndataset, dataset_lock);
# Pass __TIZEN__ to the compiler
build_platform = 'tizen'
add_project_arguments('-D__TIZEN__=1', language:['c','cpp'])
+
+ if get_option('enable-tizen-feature-check')
+ add_project_arguments('-D__FEATURE_CHECK_SUPPORT__', language: ['c', 'cpp'])
+ endif
endif
warning_flags = [
option('enable-capi', type: 'boolean', value: true)
option('enable-test', type: 'boolean', value: true)
option('enable-logging', type: 'boolean', value: true)
-
+option('enable-tizen-feature-check', type: 'boolean', value: true)
# BuildRequires: taos-ci-unittest-coverage-assessment
%endif
+%if %{with tizen}
+BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(dlog)
+%endif # tizen
+
Requires: iniparser
Requires: libopenblas_pthreads0
%endif #tizen
+## Define build options
+%define enable_tizen -Denable-tizen=false
+%define enable_tizen_feature_check -Denable-tizen-feature-check=true
+
+%if %{with tizen}
+%define enable_tizen -Denable-tizen=true
+%endif
+
# Using cblas for Matrix calculation
%if 0%{?enable_cblas}
%define enable_cblas -DUSE_BLAS=ON
mkdir -p build
meson --buildtype=plain --prefix=%{_prefix} --sysconfdir=%{_sysconfdir} \
--libdir=%{_libdir} --bindir=%{nntrainerapplicationdir} --includedir=%{_includedir}\
- -Dinstall-app=true -Denable-tizen=true %{use_gym_option} build
+ -Dinstall-app=true %{enable_tizen} %{enable_tizen_feature_check} %{use_gym_option} build
ninja -C build %{?_smp_mflags}
* @author Jijoong Moon <jijoong.moon@samsung.com>
* @bug No known bugs
*/
-#include "nntrainer_test_util.h"
+
#include <nntrainer.h>
#include <nntrainer_internal.h>
+#include <nntrainer_test_util.h>
/**
* @brief Neural Network Model Contruct / Destruct Test (possitive test )
ml_loge("Failed to init gtest\n");
}
+ /** ignore tizen feature check while running the testcases */
+ set_feature_state(SUPPORTED);
+
try {
result = RUN_ALL_TESTS();
} catch (...) {
ml_loge("Failed to run test.\n");
}
+ /** reset tizen feature check state */
+ set_feature_state(NOT_CHECKED_YET);
+
return result;
}
* @bug No known bugs
*/
-#include "nntrainer_test_util.h"
#include <nntrainer.h>
+#include <nntrainer_internal.h>
+#include <nntrainer_test_util.h>
/**
* @brief Neural Network Dataset Create / Destroy Test (negative test)
return 0;
}
+ /** ignore tizen feature check while running the testcases */
+ set_feature_state(SUPPORTED);
+
try {
result = RUN_ALL_TESTS();
} catch (...) {
std::cerr << "Error duing RUN_ALL_TSETS()" << std::endl;
}
+ /** reset tizen feature check state */
+ set_feature_state(NOT_CHECKED_YET);
+
return result;
}
* @author Jijoong Moon <jijoong.moon@samsung.com>
* @bug No known bugs
*/
-#include "nntrainer_test_util.h"
+
#include <nntrainer.h>
+#include <nntrainer_internal.h>
+#include <nntrainer_test_util.h>
/**
* @brief Neural Network Layer Create / Delete Test (possitive test)
return 0;
}
+ /** ignore tizen feature check while running the testcases */
+ set_feature_state(SUPPORTED);
+
try {
result = RUN_ALL_TESTS();
} catch (...) {
std::cerr << "Error duing RUN_ALL_TSETS()" << std::endl;
}
+ /** reset tizen feature check state */
+ set_feature_state(NOT_CHECKED_YET);
+
return result;
}
* @author Jijoong Moon <jijoong.moon@samsung.com>
* @bug No known bugs
*/
-#include "nntrainer_test_util.h"
+
#include <nntrainer.h>
+#include <nntrainer_internal.h>
+#include <nntrainer_test_util.h>
/**
* @brief Neural Network Optimizer Create / Delete Test (positive test)
return 0;
}
+ /** ignore tizen feature check while running the testcases */
+ set_feature_state(SUPPORTED);
+
try {
result = RUN_ALL_TESTS();
} catch (...) {
std::cerr << "Error duing RUN_ALL_TSETS()" << std::endl;
}
+ /** reset tizen feature check state */
+ set_feature_state(NOT_CHECKED_YET);
+
return result;
}