[ne-engine] Build fixes
authorParichay Kapoor <pk.kapoor@samsung.com>
Wed, 10 Jul 2019 07:18:29 +0000 (16:18 +0900)
committer함명주/On-Device Lab(SR)/Principal Engineer/삼성전자 <myungjoo.ham@samsung.com>
Wed, 10 Jul 2019 07:52:25 +0000 (16:52 +0900)
Added fixes to solve build error

Signed-off-by: Parichay Kapoor <pk.kapoor@samsung.com>
core/npu-engine/src/main.c
core/npu-engine/src/ne-conf.h
core/npu-engine/src/ne-inputservice.h
core/npu-engine/src/ne-mem.c
core/npu-engine/src/ne-model.h
core/npu-engine/src/ne-utils.c

index d3b3ee2..cdaa9bc 100644 (file)
@@ -38,7 +38,6 @@ static const char *helpmsg = "\
  *         -n Start as a normal process, not a daemon.
  */
 int main (int argc, char **argv) {
-  FILE *fp = NULL;
   pid_t process_id = 0;
   pid_t sid = 0;
   int daemon_mode = 1;
index 5a82fe4..7e62f5d 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef NE_CONF_H__
 #define NE_CONF_H__
 
+#include <stdint.h>
+
 /**
  * @brief The global environmental and configuration values
  * @detail The list may keep grow.
index 110ee60..16a69f8 100644 (file)
@@ -22,6 +22,9 @@
 #include <pthread.h>
 #include "ne-inf.h"
 
+typedef struct _inputservice inputservice;
+typedef struct _n40_data n40_data;
+
 typedef enum {
   HALT_NOW,
   HALT_NEXT,
@@ -41,7 +44,7 @@ typedef enum {
  *         Then, the interface of N4 should be updated to support
  *         independent scheduling for each core from N3.
  */
-typedef struct {
+struct _inputservice {
   int initialized; /**< Set 1 if it's initialized */
   void *pdata; /**< The N4x inputservice plugin's private data structure. */
 
@@ -66,17 +69,17 @@ typedef struct {
   int (*next) (inputservice *me, n40_data *data);
     /**< N4C may call getNextBuffer() and move to the next buffer for input after next has returned.
          n40_data::inbuf will be updated before calling this. */
-} inputservice;
+};
 
 /**
  * @brief Data shared between N4C and N40-plugins (N4x). N4C will keep it and N40 will have access to it via configure and next.
  */
-typedef struct {
+struct _n40_data {
   void *cb_data; /**< N3's private data for the callback */
   output_ready cb; /**< N3's callback */
   inputservice *n; /**< The N4x plugin, "inputservice" */
   buffer *inbuf; /**< The buffer for next input. Acquire mutex when you access this. (caller might have acquired) */
-} n40_data;
+};
 
 /**
  * @brief Register the input service implementation for N4C.
index 20c9f45..75579c0 100644 (file)
@@ -28,7 +28,7 @@
 #define GEM_NAME "cgem" /* cma gem */
 
 /**
- * @brief memory allocator's lock for private data 
+ * @brief memory allocator's lock for private data
  */
 #define MEM_LOCK() pthread_mutex_lock(&mpriv.mutex)
 #define MEM_UNLOCK() pthread_mutex_unlock(&mpriv.mutex)
@@ -87,7 +87,7 @@ typedef struct {
  */
 typedef struct {
   int fd;                              /**< file descriptor of a GEM driver */
-  int dmabuf;                          /**< dmabuf fd handle */ 
+  int dmabuf;                          /**< dmabuf fd handle */
   uint32_t handle;                     /**< GEM buffer object handle for memory pool */
   uint64_t size;                       /**< memory pool size */
 
@@ -172,7 +172,7 @@ chunk_set_state (chunk *target, chunk_state state)
 /**
  * @brief create new chunk instance
  * @param[in] offset offset
- * @param[in] size size 
+ * @param[in] size size
  * @return chunk instance, if no memory, NULL
  */
 static chunk *
@@ -188,7 +188,7 @@ chunk_new (uint64_t offset, uint64_t size)
   new_chunk->state = CHUNK_STATE_FREE;
 
   /* control its state */
-  pthread_mutex_init (&new_chunk->mutex, NULL); 
+  pthread_mutex_init (&new_chunk->mutex, NULL);
 
   return new_chunk;
 }
@@ -309,15 +309,15 @@ chunk_alloc (uint64_t size)
   list_for_each_entry (cur, mpriv.free_chunks, list) {
     if (cur->size >= size) {
       offset = cur->offset;
-      
+
       cur->offset += size;
       cur->size -= size;
-      
+
       if (cur->size == 0) {
         list_del (&mpriv.free_chunks, &cur->list);
         free (cur);
       }
-      
+
       break;
     }
   }
@@ -346,7 +346,7 @@ chunk_return (chunk *target)
 }
 
 /**
- * @brief create a chunk with new size 
+ * @brief create a chunk with new size
  * @param[in] target the chunk instance
  * @param[in] size size to be changed
  * @return new chunk instance
@@ -354,20 +354,20 @@ chunk_return (chunk *target)
 static chunk*
 chunk_resize (chunk *target, uint64_t size)
 {
-  chunk_state state;  
+  chunk_state state;
 
   assert (target != NULL);
   assert (size > 0);
 
   /**
-   * just return old chunk and alloc new chunk (to minimize fragmentations) 
+   * just return old chunk and alloc new chunk (to minimize fragmentations)
    * but, we need to restore its chunk state after allocation
    */
-  state = target->state; 
-  
+  state = target->state;
+
   chunk_return (target);
   target = chunk_alloc (size);
-  
+
   target->state = state;
 
   return target;
@@ -384,9 +384,9 @@ chunk_get_largest (void)
 
   list_for_each_entry (cur, mpriv.free_chunks, list) {
     if (largest) {
-      if (largest->size < cur->size) 
+      if (largest->size < cur->size)
         largest = cur;
-    } else 
+    } else
       largest = cur;
   }
 
@@ -397,7 +397,7 @@ chunk_get_largest (void)
  * @brief memory compaction algorithm
  * @note This memory compaction algorithm is similar to one implemented by Mel Gorman
  *       (refer to https://lwn.net/Articles/368869).
- *       
+ *
  *       It first starts at TOP to find a used chunk which is not busy.
  *       then, starting at BOTTOM, it searchs the free chunk where the used chunk is migrated.
  *       After compaction, a newly created free chunk can be merged with prev or next chunks.
@@ -451,7 +451,7 @@ chunk_compact_try (uint64_t *offset_dst)
           list_del (&mpriv.used_chunks, &target->list);
 
           return target;
-        } else 
+        } else
         /* case 2) this chunk is directly attached to the free chunk */
         if (free_chunk->offset + free_chunk->size == target->offset) {
           *offset_dst = target->offset - free_chunk->size;
@@ -499,12 +499,12 @@ chunk_compact (uint64_t size)
 
     /* try to perform compaction */
     target = chunk_compact_try (&offset);
-    /* no available free memory; stop compaction */ 
+    /* no available free memory; stop compaction */
     if (target == NULL)
       break;
 
     /* apply compaction as we detected */
-    memcpy ((void*) ((uint64_t) mpriv.virtaddr + offset), 
+    memcpy ((void*) ((uint64_t) mpriv.virtaddr + offset),
         (void*) ((uint64_t) mpriv.virtaddr + target->offset), target->size);
 
     target->offset = offset;
@@ -517,7 +517,7 @@ chunk_compact (uint64_t size)
   return (chunk_get_largest() >= size);
 }
 
-/* hwmem */ 
+/* hwmem */
 
 /**
  * @brief create new instance of hwmem (and use mmap() with a target offset)
@@ -588,14 +588,14 @@ hwmem_resize (hwmem *hwmem, uint64_t size)
     assert (priv->chunk != NULL);
 
     priv->chunk = chunk_resize (priv->chunk, size);
-    if (priv->chunk) 
+    if (priv->chunk)
       hwmem->size = size;
   }
 
   return (hwmem->size == size);
 }
 
-/* buffer */ 
+/* buffer */
 
 /**
  * @brief create new instance of I/O buffer
@@ -607,14 +607,14 @@ buffer_create (uint64_t size)
 {
   buffer * new_buffer = NULL;
   hwmem * new_hwmem = hwmem_alloc (size, HWMEM_TYPE_BUFFER);
-  if (!new_hwmem && chunk_compact (size)) 
+
+  if (!new_hwmem && chunk_compact (size))
     /* try again after compaction */
     new_hwmem = hwmem_alloc (size, HWMEM_TYPE_BUFFER);
 
   if (new_hwmem) {
     buffer_priv *priv = malloc (sizeof (buffer_priv));
-    
+
     priv->state = BUFFER_STATE_EMPTY;
     priv->hwmem = new_hwmem;
 
@@ -636,7 +636,7 @@ buffer_destroy (buffer *buffer)
   assert (buffer->priv);
 
   hwmem_free (((buffer_priv *) buffer->priv)->hwmem);
-  
+
   free (buffer->priv);
   free (buffer);
 }
@@ -653,7 +653,7 @@ buffer_resize (buffer** buffer_p, uint64_t size)
   assert (buffer_p);
 
   if (size == 0) {
-    if (*buffer_p) 
+    if (*buffer_p)
       buffer_destroy (*buffer_p);
     *buffer_p = NULL;
     return true;
@@ -664,7 +664,7 @@ buffer_resize (buffer** buffer_p, uint64_t size)
       assert (priv);
 
       return hwmem_resize (priv->hwmem, size);
-    } else 
+    } else
       return ((*buffer_p = buffer_create (size)) != NULL);
   }
 }
@@ -675,7 +675,7 @@ buffer_resize (buffer** buffer_p, uint64_t size)
  * @param[in] state the buffer state to be changed
  * @return 0 if no error, otherwise a negative error value
  */
-static int 
+static int
 buffer_change_state (buffer_priv *priv, buffer_state state)
 {
   bool state_changed = false;
@@ -719,7 +719,7 @@ buffer_change_state (buffer_priv *priv, buffer_state state)
     default:
       break;
   }
+
   if (!state_changed)
     RETURN_ERROR (EINVAL);
 
@@ -734,7 +734,7 @@ buffer_change_state (buffer_priv *priv, buffer_state state)
 
 /**
  * @brief initialize memory allocator and reserve its memory pool (physically contiguous).
- * @param[in] size_in the maximum memory size of memory pool 
+ * @param[in] size_in the maximum memory size of memory pool
  * @param[out] size_out the allocated size (i.e., zero means a failure)
  * @return 0 if no error, otherwise a negative error value
  *
@@ -758,7 +758,7 @@ mem_init (uint64_t size_in, uint64_t *size_out)
 
   do {
     /**
-     * the minimum size of allocation is MEM_BASE_SIZE 
+     * the minimum size of allocation is MEM_BASE_SIZE
      * note that gem_create() supports only 32bit allocation (currently)
      */
     uint32_t size_in_32 = size_in;
@@ -829,7 +829,6 @@ mem_fini (void)
     if (mpriv.buffer[idx]) {
       buffer_destroy (mpriv.buffer[idx]);
       mpriv.buffer[idx] = NULL;
-      mpriv.buffer_idx[idx] = 0;
     }
   }
   mpriv.buffer_size = 0;
@@ -844,11 +843,11 @@ mem_fini (void)
     list_del (&mpriv.free_chunks, &chunk->list);
     chunk_free (chunk);
   }
-  
+
   munmap (mpriv.virtaddr, mpriv.size);
 
   /* close dmabuf handle */
-  close (mpriv.dmabuf); 
+  close (mpriv.dmabuf);
 
   /* release the gem buffer object handle */
   gem_destroy (mpriv.fd, mpriv.handle);
@@ -864,7 +863,7 @@ mem_fini (void)
  * @param[in] size the requested memory size
  * @param[out] hwmem_p if no error, otherwise NULL pointer
  * @return 0 if no error, otherwise a negative error value
- * 
+ *
  * @note its latency can be increased due to the memory compaction.
  */
 static int
@@ -879,16 +878,16 @@ mem_alloc (uint64_t size, hwmem **hwmem_p)
 
   new_hwmem = hwmem_alloc (size, HWMEM_TYPE_MODEL);
 
-  if (!new_hwmem && chunk_compact (size)) 
+  if (!new_hwmem && chunk_compact (size))
     /* try again after compaction */
     new_hwmem = hwmem_alloc (size, HWMEM_TYPE_MODEL);
 
   MEM_UNLOCK();
 
-  if (new_hwmem) { 
-    *hwmem_p = new_hwmem; 
+  if (new_hwmem) {
+    *hwmem_p = new_hwmem;
     return 0;
-  } else 
+  } else
     RETURN_ERROR (ENOMEM);
 }
 
@@ -897,7 +896,7 @@ mem_alloc (uint64_t size, hwmem **hwmem_p)
  * @param[in] hwmem the created hwmem instance
  * @param[in] size the new memory size
  * @return 0 if no error, otherwise a negative error value
- * 
+ *
  * @note its latency can be increased due to the memory compaction.
  */
 static int
@@ -975,9 +974,9 @@ mem_resize_buffers (uint64_t size)
         mpriv.buffer_head = 0;
         buffer_change_state (priv, BUFFER_STATE_EMPTY);
 
-        /** 
-         * Theses buffers are always activated. 
-         * after buffer configuration, it can not be affected by compaction 
+        /**
+         * Theses buffers are always activated.
+         * after buffer configuration, it can not be affected by compaction
          */
         hwmem_activate (priv->hwmem);
       }
@@ -1007,9 +1006,9 @@ mem_switch_buffers (void)
   /* wait until the buffer head becomes input ready */
   while (buffer_get_state (buf) != BUFFER_STATE_INPUT_READY)
     MEM_WAIT();
-  
+
   mpriv.buffer_head = (mpriv.buffer_head + 1) % MEM_NUM_BUFFERS;
-  
+
   /* notify buffer head is changed */
   MEM_WAKEUP();
   MEM_UNLOCK();
@@ -1020,7 +1019,7 @@ mem_switch_buffers (void)
  * @param[in] role the role of buffer
  * @return the target buffer
  */
-static buffer* 
+static buffer*
 wait_until_available (buffer_role role)
 {
   buffer *buf = NULL;
@@ -1067,7 +1066,7 @@ wait_until_available (buffer_role role)
 out:
   MEM_UNLOCK ();
 
-  return buffer;
+  return buf;
 }
 
 /**
@@ -1087,7 +1086,7 @@ mem_get_next_buffer (buffer_role role)
 
   buf = wait_until_available (role);
   if (buf) {
-    buffer_priv *priv = buf->priv; 
+    buffer_priv *priv = buf->priv;
 
     hwmem_activate (priv->hwmem);
   }
@@ -1099,10 +1098,10 @@ out:
 /**
  * @brief return the buffer for next requesters
  * @param[in] buffer the buffer instance
- * @return 0 if no error, otherwise negative values  
+ * @return 0 if no error, otherwise negative values
  *
  * @note this should be called after finishing some processing with this buffer.
- *       then, the caller does not use this buffer anymore, but its contents 
+ *       then, the caller does not use this buffer anymore, but its contents
  *       would be valid for other users.
  */
 static int
@@ -1133,7 +1132,7 @@ mem_return_buffer (buffer *buf)
   MEM_UNLOCK();
 
   /* deactivate buffer */
-  if (err == 0) 
+  if (err == 0)
     hwmem_deactivate (priv->hwmem);
 
   RETURN_ERROR (err);
@@ -1141,7 +1140,7 @@ mem_return_buffer (buffer *buf)
 
 /**
  * @brief get the memory pool size
- * @return the memory pool size 
+ * @return the memory pool size
  */
 static uint64_t
 mem_get_size (void)
@@ -1184,11 +1183,11 @@ static mem mem_instance = {
  * @param[out] offset its offset
  * @return 0 if no error, otherwise a negative error value
  */
-int 
+int
 hwmem_get_offset (hwmem *hwmem, uint64_t *offset)
 {
   hwmem_priv *priv;
+
   if (!hwmem || !hwmem->priv)
     RETURN_ERROR_MSG (EINVAL, "invalid hwmem; internal structure does not exist");
 
@@ -1212,7 +1211,7 @@ hwmem_get_offset (hwmem *hwmem, uint64_t *offset)
 int hwmem_get_data (hwmem *hwmem, void **ptr)
 {
   hwmem_priv *priv;
+
   if (!hwmem || !hwmem->priv)
     RETURN_ERROR_MSG (EINVAL, "invalid hwmem; internal structure does not exist");
 
@@ -1238,7 +1237,7 @@ int
 hwmem_activate (hwmem *hwmem)
 {
   hwmem_priv *priv;
+
   if (!hwmem || !hwmem->priv)
     RETURN_ERROR_MSG (EINVAL, "invalid hwmem; internal structure does not exist");
 
@@ -1261,7 +1260,7 @@ int
 hwmem_deactivate (hwmem *hwmem)
 {
   hwmem_priv *priv;
+
   if (!hwmem || !hwmem->priv)
     RETURN_ERROR_MSG (EINVAL, "invalid hwmem; internal structure does not exist");
 
@@ -1286,7 +1285,7 @@ int
 buffer_get_hwmem (buffer *buffer, hwmem **hwmem)
 {
   buffer_priv *priv;
+
   if (!buffer || !buffer->priv)
     RETURN_ERROR_MSG (EINVAL, "invalid hwmem; internal structure does not exist");
 
@@ -1294,7 +1293,7 @@ buffer_get_hwmem (buffer *buffer, hwmem **hwmem)
     RETURN_ERROR_MSG (EINVAL, "invalid hwmem pointer");
 
   priv = buffer->priv;
-  *hwmem = priv->hwmem; 
+  *hwmem = priv->hwmem;
 
   return 0;
 }
@@ -1304,11 +1303,11 @@ buffer_get_hwmem (buffer *buffer, hwmem **hwmem)
  * @param[in] buffer the buffer instance
  * @return buffer state
  */
-buffer_state 
+buffer_state
 buffer_get_state (buffer *buffer)
 {
   buffer_priv *priv;
+
   if (!buffer || !buffer->priv)
     return BUFFER_STATE_INVAL;
 
@@ -1322,7 +1321,7 @@ buffer_get_state (buffer *buffer)
  * @return mem instance
  */
 mem *
-mem_get_instance (void) 
+mem_get_instance (void)
 {
  return &mem_instance;
 }
index 936d8b2..1b80a71 100644 (file)
@@ -25,6 +25,7 @@
  * @brief Represent a submodel of a model. Loaded with npubin_fmt_submodel.
  */
 typedef struct _submodel submodel;
+typedef struct _model model;
 
 struct _submodel {
   const npubin_submeta *meta;
@@ -37,7 +38,7 @@ struct _submodel {
 /**
  * @brief Represent a model loaded. Loaded with npubin_fmt.
  */
-typedef struct {
+struct _model {
   const npubin_meta *meta;
   const hwmem *memblock; /**< The H/W memory block containing the model */
 
@@ -45,6 +46,6 @@ typedef struct {
   uint64_t inputSequence;
 
   list submodels; /**< The list of submodels, ne-utils.h */
-} model;
+};
 
 #endif /* __NPU_ENGINE_N7p_MODEL_HH__ */
index fae0194..09cd132 100644 (file)
  * @bug No known bugs except for NYI items
  */
 
-#include <ne-utils.h>
 #include <assert.h>
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
 #include <time.h>
+
+#include "ne-utils.h"
 #include "ne-conf.h"
 
 void fini_logwrite (void) __attribute__ ((destructor));
@@ -28,7 +30,7 @@ void fini_logwrite (void) __attribute__ ((destructor));
  * @brief internal function to initialize a list head
  * @param[in] head the list head
  */
-static void 
+static void
 list_head_init (list_node *head)
 {
   head->prev = head->next = head;
@@ -54,7 +56,7 @@ list_init (list *list)
 bool
 list_is_first (list *list, list_node *node)
 {
-  return list->head.next == node;  
+  return list->head.next == node;
 }
 
 /**
@@ -132,7 +134,7 @@ list_add_next (list *list, list_node *node, list_node *next)
  * @param[in] prev previous list node
  * @param[in] next next list node
  */
-static void 
+static void
 _list_del (list_node *prev, list_node *next)
 {
   next->prev = prev;
@@ -176,7 +178,7 @@ hash_table_init (hash_table *ht, uint32_t size)
   if (ht->list == NULL)
     return -ENOMEM;
 
-  for (i = 0; i < size; i++) 
+  for (i = 0; i < size; i++)
     list_init (&ht->list[i]);
 
   return 0;
@@ -283,7 +285,7 @@ void logwrite(loglevel l, module m, const char *format, ...) {
   va_list args;
   time_t ltime;
   char* time_str;
+
   ltime = time(NULL);
 
   if (fp == NULL) {