Introduce namespace in runtime load helper (#3494)
author오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 7 Nov 2018 06:18:40 +0000 (15:18 +0900)
committer이춘석/동작제어Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>
Wed, 7 Nov 2018 06:18:40 +0000 (15:18 +0900)
Introduce namespace in runtime load helper
Restore function name
It protects naming conflict with upstream tensorflow

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
include/NeuralNetworksLoadHelpers.h

index 16b1f35..06934cc 100644 (file)
@@ -41,7 +41,7 @@
  * @param[in] name    Name of a function
  */
 #define LOAD_FUNCTION(name)                                                    \
-  static name##_fn fn = reinterpret_cast<name##_fn>(loadNNAPIFunction(#name));
+  static name##_fn fn = reinterpret_cast<name##_fn>(nnfw::loadFunction(#name));
 
 /**
  * @brief Run @c fn function. @c fn is created by @ref LOAD_FUNCTION
  */
 #define EXECUTE_FUNCTION_RETURN(...) return fn != nullptr ? fn(__VA_ARGS__) : 0;
 
+namespace nnfw
+{
+
 /**
  * @brief Load NN API library
  * @param[in] name path of NN API library
  * @return a symbol table handle of NN API library
  */
-inline void* loadNNAPILibrary(const char* name) {
+inline void* loadLibrary(const char* name) {
   // TODO: change RTLD_LOCAL? Assumes there can be multiple instances of nn
   // api RT
   void* handle = dlopen(name, RTLD_LAZY | RTLD_LOCAL);
@@ -78,8 +81,8 @@ inline void* loadNNAPILibrary(const char* name) {
  * @brief Load libneuralnetworks.so and return handle of library
  * @return a symbol table handle of NN API library
  */
-inline void* getNNAPILibraryHandle() {
-  static void* handle = loadNNAPILibrary("libneuralnetworks.so");
+inline void* getLibraryHandle() {
+  static void* handle = loadLibrary("libneuralnetworks.so");
   return handle;
 }
 
@@ -88,10 +91,10 @@ inline void* getNNAPILibraryHandle() {
  * @param[in] name    Name of function
  * @return function pointer
  */
-inline void* loadNNAPIFunction(const char* name) {
+inline void* loadFunction(const char* name) {
   void* fn = nullptr;
-  if (getNNAPILibraryHandle() != nullptr) {
-    fn = dlsym(getNNAPILibraryHandle(), name);
+  if (getLibraryHandle() != nullptr) {
+    fn = dlsym(getLibraryHandle(), name);
   }
   if (fn == nullptr)
   {
@@ -114,8 +117,10 @@ inline void* loadNNAPIFunction(const char* name) {
  * @return @c true if loading is successful, otherwise @c false.
  */
 inline bool NNAPIExists() {
-  static bool nnapi_is_available = getNNAPILibraryHandle();
+  static bool nnapi_is_available = getLibraryHandle();
   return nnapi_is_available;
 }
 
+} // namespace nnfw
+
 #endif // __NEURAL_NETWORKS_LOAD_HELPER_H__