Remove default flag about tensorflow memory optimization.
In tensorflow sub-plugin, read this option using custom-bool function.
Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
}
}
- tf_mem_optmz = nnsconf_get_value_bool (NNSCONF_VAL_TF_MEM_OPTMZ);
+ tf_mem_optmz = nnsconf_get_custom_value_bool ("tensorflow",
+ "enable_mem_optimization", FALSE);
tf = g_new0 (tf_data, 1); /** initialize tf Fill Zero! */
*private_data = tf;
gchar *pathFILTERS[CONF_SOURCES]; /**< directory paths for FILTERS */
gchar *pathDECODERS[CONF_SOURCES]; /**< directory paths for DECODERS */
gchar *pathCUSTOM_FILTERS[CONF_SOURCES]; /**< directory paths for CUSTOM FILTERS */
- gchar *valueTF_MEM_OPTMZ[CONF_SOURCES]; /**< value of TF_MEM_OPTMZ */
/*************************************************
* Processed Values *
gchar **basenameFILTERS; /**< Null terminated list of basenames for FILTERS */
gchar **basenameDECODERS;; /**< Null terminated list of basenames for DECODERS */
gchar **basenameCUSTOM_FILTERS; /**< Null terminated list of basenames for CUSTOM FILTERS */
-
- gboolean boolTF_MEM_OPTMZ; /**< The flag to decide using memcpy or not at Tensorflow in boolean type */
} confdata;
static confdata conf = { 0 };
g_free (conf.pathFILTERS[i]);
g_free (conf.pathDECODERS[i]);
g_free (conf.pathCUSTOM_FILTERS[i]);
- g_free (conf.valueTF_MEM_OPTMZ[i]);
}
g_strfreev (conf.filesFILTERS);
conf.pathFILTERS[0] = _strdup_getenv (NNSTREAMER_ENVVAR_FILTERS);
conf.pathDECODERS[0] = _strdup_getenv (NNSTREAMER_ENVVAR_DECODERS);
conf.pathCUSTOM_FILTERS[0] = _strdup_getenv (NNSTREAMER_ENVVAR_CUSTOMFILTERS);
- conf.valueTF_MEM_OPTMZ[0] = _strdup_getenv (NNSTREAMER_ENVVAR_TF_MEM_OPTMZ);
/* Read the conf file. It's ok even if we cannot load it. */
if (conf.conffile &&
g_key_file_get_string (key_file, "decoder", "decoders", &error);
conf.pathCUSTOM_FILTERS[1] =
g_key_file_get_string (key_file, "filter", "customfilters", &error);
- conf.valueTF_MEM_OPTMZ[1] =
- g_key_file_get_string (key_file, "tensorflow", "mem_optmz", &error);
}
/* Strdup the hardcoded */
conf.pathFILTERS[2] = g_strdup (NNSTREAMER_FILTERS);
conf.pathDECODERS[2] = g_strdup (NNSTREAMER_DECODERS);
conf.pathCUSTOM_FILTERS[2] = g_strdup (NNSTREAMER_CUSTOM_FILTERS);
- conf.valueTF_MEM_OPTMZ[2] = g_strdup (NNSTREAMER_TF_MEM_OPTMZ);
/* Fill in conf.files* */
_fill_in_vstr (&conf.filesFILTERS, &conf.basenameFILTERS, conf.pathFILTERS,
_fill_in_vstr (&conf.filesCUSTOM_FILTERS, &conf.basenameCUSTOM_FILTERS,
conf.pathCUSTOM_FILTERS, NNSCONF_PATH_CUSTOM_FILTERS);
- /* Fill in conf.bool values */
- for (i = 0; i < CONF_SOURCES; i++) {
- if (conf.valueTF_MEM_OPTMZ[i] && conf.valueTF_MEM_OPTMZ[i][0]) {
- if (!g_ascii_strncasecmp ("1", conf.valueTF_MEM_OPTMZ[i], 1) || /* 1 */
- !g_ascii_strncasecmp ("t", conf.valueTF_MEM_OPTMZ[i], 1) || /* True */
- !g_ascii_strncasecmp ("on", conf.valueTF_MEM_OPTMZ[i], 2) || /* On */
- !g_ascii_strncasecmp ("y", conf.valueTF_MEM_OPTMZ[i], 1)) /* Yes */
- conf.boolTF_MEM_OPTMZ = TRUE;
- else
- conf.boolTF_MEM_OPTMZ = FALSE;
- break;
- }
- }
-
conf.loaded = TRUE;
return TRUE;
}
return g_strv_length (vstr);
}
-/** @brief Public function defined in the header */
-gboolean
-nnsconf_get_value_bool (nnsconf_type_value type)
-{
- gboolean ret = FALSE;
-
- nnsconf_loadconf (FALSE);
-
- switch (type) {
- case NNSCONF_VAL_TF_MEM_OPTMZ:
- ret = conf.boolTF_MEM_OPTMZ;
- break;
- default:
- break;
- }
-
- return ret;
-}
-
/**
* @brief Internal cache for the custom key-values
*/
#define NNSTREAMER_ENVVAR_FILTERS "NNSTREAMER_FILTERS"
#define NNSTREAMER_ENVVAR_DECODERS "NNSTREAMER_DECODERS"
#define NNSTREAMER_ENVVAR_CUSTOMFILTERS "NNSTREAMER_CUSTOMFILTERS"
-#define NNSTREAMER_ENVVAR_TF_MEM_OPTMZ "NNSTREAMER_TF_MEM_OPTMZ"
/* Internal Hardcoded Values */
#define NNSTREAMER_DEFAULT_CONF_FILE "/etc/nnstreamer.ini"
#define NNSTREAMER_FILTERS "/usr/lib/nnstreamer/filters/"
#define NNSTREAMER_DECODERS "/usr/lib/nnstreamer/decoders/"
#define NNSTREAMER_CUSTOM_FILTERS "/usr/lib/nnstreamer/customfilters/"
-#define NNSTREAMER_TF_MEM_OPTMZ "false"
/**
* Note that users still can place their custom filters anywhere if they
* designate them with the full path.
NNSCONF_PATH_END,
} nnsconf_type_path;
-typedef enum {
- NNSCONF_VAL_TF_MEM_OPTMZ = 0,
-
- NNSCONF_VAL_END,
-} nnsconf_type_value;
-
/**
* @brief Load the .ini file
* @param[in] force_reload TRUE if you want to clean up and load conf again.
nnsconf_get_subplugin_info (nnsconf_type_path type, subplugin_info_s * info);
/**
- * @brief Get the configured boolean values for the type
- * @param[in] type The type (TF_MEM_OPTMZ)
- * @return The boolean value to the file. Caller MUST NOT modify this.
- * Returns FALSE if we cannot find the file or the value as a DEFAULT.
- */
-extern gboolean
-nnsconf_get_value_bool (nnsconf_type_value type);
-
-/**
* @brief Get the custom configuration value from .ini and envvar.
* @detail For predefined configurations defined in this header,
* use the given enum for faster configuration processing.
# Set 1 or TRUE if you want to eliminate memcpy of tensorflow input frames for faster executions.
# It may break in some special cases (running tensorflow & nnstreamer in a chroot of a AWS VM); in such a case, keep it 0 or FALSE.
[tensorflow]
-mem_optmz=@TF_MEM_OPTMZ@
+enable_mem_optimization=@TF_MEM_OPTMZ@
# Set 1 or TRUE if you want to use NNAPI with tensorflow-lite, which enables to use NNAPI backend, which may use GPU or NPU/TPU.
[tensorflowlite]
export GST_PLUGIN_PATH=$(pwd)/gst/nnstreamer
export NNSTREAMER_FILTERS=$(pwd)/ext/nnstreamer/tensor_filter
export NNSTREAMER_DECODERS=$(pwd)/ext/nnstreamer/tensor_decoder
- %ifarch x86_64 aarch64
- export NNSTREAMER_TF_MEM_OPTMZ=0
- %endif
./tests/unittest_common
./tests/unittest_sink --gst-plugin-path=.
./tests/unittest_plugins --gst-plugin-path=.
FILE *fp = g_fopen (filename, "w");
const gchar *fn;
- gchar *confenv = g_strdup (g_getenv ("NNSTREAMER_CONF"));
- gchar *tfmemopt = g_strdup (g_getenv ("NNSTREAMER_TF_MEM_OPTMZ"));
+ const gchar *base_confenv;
+ gchar *confenv;
+ base_confenv = g_getenv ("NNSTREAMER_CONF");
+ confenv = (base_confenv != NULL) ? g_strdup (base_confenv) : NULL;
- EXPECT_TRUE (fp != NULL);
+ ASSERT_TRUE (fp != NULL);
+ g_fprintf (fp, "[common]\n");
+ g_fprintf (fp, "enable_envvar=True\n");
g_fprintf (fp, "[filter]\n");
g_fprintf (fp, "filters=%s\n", dirf);
g_fprintf (fp, "customfilters=%s\n", dircf);
g_fprintf (fp, "[decoder]\n");
g_fprintf (fp, "decoders=%s\n", dird);
- g_fprintf (fp, "[tensorflow]\n");
- g_fprintf (fp, "mem_optmz=true\n");
g_fprintf (fp, "[customX]\n");
g_fprintf (fp, "abc=OFF\n");
g_fprintf (fp, "def=on\n");
gchar *f6 = create_null_file (dircf, "fastfaster.so");
EXPECT_TRUE (FALSE != g_setenv ("NNSTREAMER_CONF", filename, TRUE));
- EXPECT_TRUE (FALSE != g_setenv ("NNSTREAMER_TF_MEM_OPTMZ", "", TRUE));
EXPECT_TRUE (nnsconf_loadconf (TRUE) == TRUE);
fn = nnsconf_get_fullpath ("fantastic", NNSCONF_PATH_FILTERS);
fn = nnsconf_get_fullpath ("notfound", NNSCONF_PATH_CUSTOM_FILTERS);
EXPECT_STREQ (fn, NULL);
- EXPECT_EQ (nnsconf_get_value_bool (NNSCONF_VAL_TF_MEM_OPTMZ), TRUE);
-
EXPECT_TRUE (check_custom_conf ("customX", "abc", "OFF"));
EXPECT_FALSE (nnsconf_get_custom_value_bool ("customX", "abc", TRUE));
EXPECT_FALSE (nnsconf_get_custom_value_bool ("customX", "abc", FALSE));
EXPECT_FALSE (nnsconf_get_custom_value_bool ("customW", "n05", FALSE));
EXPECT_TRUE (nnsconf_get_custom_value_bool ("customW", "n05", TRUE));
-
- g_setenv ("NNSTREAMER_CONF", confenv, TRUE);
- g_setenv ("NNSTREAMER_TF_MEM_OPTMZ", tfmemopt, TRUE);
- g_free (confenv);
+ if (confenv) {
+ g_setenv ("NNSTREAMER_CONF", confenv, TRUE);
+ g_free (confenv);
+ } else {
+ g_unsetenv ("NNSTREAMER_CONF");
+ }
g_free (f1);
g_free (f2);
g_free (f3);