[databuffer] Cleanup databuffers for ccapi
authorParichay Kapoor <pk.kapoor@samsung.com>
Mon, 12 Oct 2020 01:23:55 +0000 (10:23 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Mon, 19 Oct 2020 01:18:30 +0000 (10:18 +0900)
Cleanup databuffer headers for ccapi

See also #199

**Self evaluation:**
1. Build test: [x]Passed [ ]Failed [ ]Skipped
2. Run test: [x]Passed [ ]Failed [ ]Skipped

Signed-off-by: Parichay Kapoor <pk.kapoor@samsung.com>
nntrainer/include/databuffer.h
nntrainer/include/databuffer_file.h
nntrainer/include/databuffer_func.h
nntrainer/include/databuffer_util.h [new file with mode: 0644]
nntrainer/meson.build
nntrainer/src/databuffer.cpp
nntrainer/src/databuffer_file.cpp
nntrainer/src/databuffer_func.cpp
packaging/nntrainer.spec

index 064806148faa1bfba4127f89cbe1f8a52b3c9bd7..5f04c4a9265f9b1b9f3216718e5eaa2d61a934dd 100644 (file)
 #define __DATABUFFER_H__
 #ifdef __cplusplus
 
-#include <atomic>
-#include <fstream>
-#include <functional>
-#include <iostream>
 #include <memory>
 #include <random>
 #include <thread>
 
 #include <tensor_dim.h>
 
-#define SET_VALIDATION(val)                                              \
-  do {                                                                   \
-    for (DataType i = DATA_TRAIN; i < DATA_UNKNOWN; i = DataType(i + 1)) \
-      validation[i] = val;                                               \
-  } while (0)
-
-#define NN_EXCEPTION_NOTI(val)                             \
-  do {                                                     \
-    switch (type) {                                        \
-    case BUF_TRAIN: {                                      \
-      std::lock_guard<std::mutex> lgtrain(readyTrainData); \
-      trainReadyFlag = val;                                \
-      cv_train.notify_all();                               \
-    } break;                                               \
-    case BUF_VAL: {                                        \
-      std::lock_guard<std::mutex> lgval(readyValData);     \
-      valReadyFlag = val;                                  \
-      cv_val.notify_all();                                 \
-    } break;                                               \
-    case BUF_TEST: {                                       \
-      std::lock_guard<std::mutex> lgtest(readyTestData);   \
-      testReadyFlag = val;                                 \
-      cv_test.notify_all();                                \
-    } break;                                               \
-    default:                                               \
-      break;                                               \
-    }                                                      \
-  } while (0)
-
-/**
- * @brief Number of Data Set
- */
-constexpr const unsigned int NBUFTYPE = 4;
-
-typedef enum {
-  DATA_NOT_READY = 0,
-  DATA_READY = 1,
-  DATA_END = 2,
-  DATA_ERROR = 3,
-} DataStatus;
-
 namespace nntrainer {
 
 /**
@@ -211,7 +166,6 @@ public:
    * @retval #ML_ERROR_NONE Successful.
    * @retval #ML_ERROR_INVALID_PARAMETER invalid parameter.
    */
-  /* virtual int setFeatureSize(unsigned int n); */
   virtual int setFeatureSize(TensorDim indim);
 
   /**
@@ -255,20 +209,13 @@ public:
   int setProperty(std::vector<std::string> values);
 
   /**
-   * @brief     set property
+   * @brief     set property to allow setting user_data for cb
    * @param[in] values values of property
    * @retval #ML_ERROR_NONE Successful.
    * @retval #ML_ERROR_INVALID_PARAMETER invalid parameter.
    */
   int setProperty(std::vector<void *> values);
 
-  /**
-   * @brief     status of thread
-   */
-  DataStatus trainReadyFlag;
-  DataStatus valReadyFlag;
-  DataStatus testReadyFlag;
-
   enum class PropertyType {
     train_data = 0,
     val_data = 1,
@@ -279,6 +226,28 @@ public:
   };
 
 protected:
+  /**
+   * @brief Number of Data Set
+   */
+  static constexpr const unsigned int NBUFTYPE = 4;
+
+  /**
+   * @brief state of the data buffer while getting the data
+   */
+  typedef enum {
+    DATA_NOT_READY = 0,
+    DATA_READY = 1,
+    DATA_END = 2,
+    DATA_ERROR = 3,
+  } DataStatus;
+
+  /**
+   * @brief     status of thread
+   */
+  DataStatus trainReadyFlag;
+  DataStatus valReadyFlag;
+  DataStatus testReadyFlag;
+
   /**
    * @brief     Data Queues for each data set
    */
index 77011c83325d5c46a762f806a9e681b60eac8e2e..4da7835d643b65c5dcc34ac84e0f294d256fc48e 100644 (file)
 #define __DATABUFFER_FILE_H__
 #ifdef __cplusplus
 
-#include <atomic>
 #include <fstream>
-#include <functional>
-#include <iostream>
 #include <memory>
 #include <thread>
 #include <vector>
index 0fe274a7eb0dcd4ecc934c9031194f40e9aacabe..362b76292b3da723dba8522f3360d04e68909079 100644 (file)
 #define __DATABUFFER_FUNC_H__
 #ifdef __cplusplus
 
-#include <atomic>
-#include <fstream>
 #include <functional>
-#include <iostream>
 #include <memory>
 #include <thread>
 #include <vector>
diff --git a/nntrainer/include/databuffer_util.h b/nntrainer/include/databuffer_util.h
new file mode 100644 (file)
index 0000000..4f67293
--- /dev/null
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: Apache-2.0
+/**
+ * Copyright (C) 2020 Parichay Kapoor <pk.kapoor@samsung.com>
+ *
+ * @file       databuffer_util.h
+ * @date       12 October 2020
+ * @see                https://github.com/nnstreamer/nntrainer
+ * @author     Jijoong Moon <jijoong.moon@samsung.com>
+ * @author     Parichay Kapoor <pk.kapoor@samsung.com>
+ * @bug                No known bugs except for NYI items
+ * @brief      This is Databuffer utility file.
+ *
+ */
+
+#define SET_VALIDATION(val)                                              \
+  do {                                                                   \
+    for (DataType i = DATA_TRAIN; i < DATA_UNKNOWN; i = DataType(i + 1)) \
+      validation[i] = val;                                               \
+  } while (0)
+
+#define NN_EXCEPTION_NOTI(val)                             \
+  do {                                                     \
+    switch (type) {                                        \
+    case BUF_TRAIN: {                                      \
+      std::lock_guard<std::mutex> lgtrain(readyTrainData); \
+      trainReadyFlag = val;                                \
+      cv_train.notify_all();                               \
+    } break;                                               \
+    case BUF_VAL: {                                        \
+      std::lock_guard<std::mutex> lgval(readyValData);     \
+      valReadyFlag = val;                                  \
+      cv_val.notify_all();                                 \
+    } break;                                               \
+    case BUF_TEST: {                                       \
+      std::lock_guard<std::mutex> lgtest(readyTestData);   \
+      testReadyFlag = val;                                 \
+      cv_test.notify_all();                                \
+    } break;                                               \
+    default:                                               \
+      break;                                               \
+    }                                                      \
+  } while (0)
index e8cc189fba398eddcd0e0241aa7e5b0e19fe9dbc..10e94f79aa3495615277923f037d21afc46bb6e8 100644 (file)
@@ -63,6 +63,7 @@ nntrainer_headers = [
   'include/databuffer.h',
   'include/databuffer_file.h',
   'include/databuffer_func.h',
+  'include/databuffer_util.h',
   'include/fc_layer.h',
   'include/flatten_layer.h',
   'include/input_layer.h',
index 3a99ea430acee2c66558fe74c32b6bca53960a84..7d17cdfc714aab3e2217561711367ca66fbc2327 100644 (file)
  *
  */
 
-#include <assert.h>
+#include <cassert>
 #include <climits>
 #include <condition_variable>
 #include <cstring>
 #include <databuffer.h>
+#include <databuffer_util.h>
 #include <functional>
 #include <iomanip>
 #include <mutex>
index e94d57f7423d673971aa4d07bccf3c5f9468863e..5dfe216876d41d7ee307cad21538709fd05e47d1 100644 (file)
@@ -26,6 +26,7 @@
 #include <condition_variable>
 #include <cstring>
 #include <databuffer_file.h>
+#include <databuffer_util.h>
 #include <functional>
 #include <iomanip>
 #include <mutex>
@@ -51,10 +52,6 @@ extern std::condition_variable cv_train;
 extern std::condition_variable cv_val;
 extern std::condition_variable cv_test;
 
-extern DataStatus trainReadyFlag;
-extern DataStatus valReadyFlag;
-extern DataStatus testReadyFlag;
-
 static long getFileSize(std::string file_name) {
   std::ifstream file_stream(file_name.c_str(), std::ios::in | std::ios::binary);
   if (file_stream.good()) {
index a37c5e79f9be174e458b3af80a57c358d0c45f75..09740b33727da704b30522e648e05248fd5bdbec 100644 (file)
@@ -26,6 +26,7 @@
 #include <condition_variable>
 #include <cstring>
 #include <databuffer_func.h>
+#include <databuffer_util.h>
 #include <functional>
 #include <iomanip>
 #include <mutex>
@@ -51,10 +52,6 @@ extern std::condition_variable cv_train;
 extern std::condition_variable cv_val;
 extern std::condition_variable cv_test;
 
-extern DataStatus trainReadyFlag;
-extern DataStatus valReadyFlag;
-extern DataStatus testReadyFlag;
-
 int DataBufferFromCallback::init() {
   int status = ML_ERROR_NONE;
 
index aad9840836f71a1972b25b7ed3377ed55da9715f..2d6aa5216d57ea8ac6cee0b8104d2a7e24972c69 100644 (file)
@@ -315,6 +315,7 @@ cp -r result %{buildroot}%{_datadir}/nntrainer/unittest/
 %{_includedir}/nntrainer/databuffer.h
 %{_includedir}/nntrainer/databuffer_file.h
 %{_includedir}/nntrainer/databuffer_func.h
+%{_includedir}/nntrainer/databuffer_util.h
 %{_includedir}/nntrainer/layer.h
 %{_includedir}/nntrainer/layer_factory.h
 %{_includedir}/nntrainer/input_layer.h