From 74e76b3f2d2e3fddd8ead930696dc47ce03b69c3 Mon Sep 17 00:00:00 2001 From: Parichay Kapoor Date: Mon, 12 Oct 2020 10:23:55 +0900 Subject: [PATCH] [databuffer] Cleanup databuffers for ccapi 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 --- nntrainer/include/databuffer.h | 77 +++++++++++-------------------------- nntrainer/include/databuffer_file.h | 3 -- nntrainer/include/databuffer_func.h | 3 -- nntrainer/include/databuffer_util.h | 42 ++++++++++++++++++++ nntrainer/meson.build | 1 + nntrainer/src/databuffer.cpp | 3 +- nntrainer/src/databuffer_file.cpp | 5 +-- nntrainer/src/databuffer_func.cpp | 5 +-- packaging/nntrainer.spec | 1 + 9 files changed, 71 insertions(+), 69 deletions(-) create mode 100644 nntrainer/include/databuffer_util.h diff --git a/nntrainer/include/databuffer.h b/nntrainer/include/databuffer.h index 0648061..5f04c4a 100644 --- a/nntrainer/include/databuffer.h +++ b/nntrainer/include/databuffer.h @@ -25,10 +25,6 @@ #define __DATABUFFER_H__ #ifdef __cplusplus -#include -#include -#include -#include #include #include #include @@ -36,47 +32,6 @@ #include -#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 lgtrain(readyTrainData); \ - trainReadyFlag = val; \ - cv_train.notify_all(); \ - } break; \ - case BUF_VAL: { \ - std::lock_guard lgval(readyValData); \ - valReadyFlag = val; \ - cv_val.notify_all(); \ - } break; \ - case BUF_TEST: { \ - std::lock_guard 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 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 values); - /** - * @brief status of thread - */ - DataStatus trainReadyFlag; - DataStatus valReadyFlag; - DataStatus testReadyFlag; - enum class PropertyType { train_data = 0, val_data = 1, @@ -280,6 +227,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 */ std::vector> train_data; diff --git a/nntrainer/include/databuffer_file.h b/nntrainer/include/databuffer_file.h index 77011c8..4da7835 100644 --- a/nntrainer/include/databuffer_file.h +++ b/nntrainer/include/databuffer_file.h @@ -25,10 +25,7 @@ #define __DATABUFFER_FILE_H__ #ifdef __cplusplus -#include #include -#include -#include #include #include #include diff --git a/nntrainer/include/databuffer_func.h b/nntrainer/include/databuffer_func.h index 0fe274a..362b762 100644 --- a/nntrainer/include/databuffer_func.h +++ b/nntrainer/include/databuffer_func.h @@ -25,10 +25,7 @@ #define __DATABUFFER_FUNC_H__ #ifdef __cplusplus -#include -#include #include -#include #include #include #include diff --git a/nntrainer/include/databuffer_util.h b/nntrainer/include/databuffer_util.h new file mode 100644 index 0000000..4f67293 --- /dev/null +++ b/nntrainer/include/databuffer_util.h @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: Apache-2.0 +/** + * Copyright (C) 2020 Parichay Kapoor + * + * @file databuffer_util.h + * @date 12 October 2020 + * @see https://github.com/nnstreamer/nntrainer + * @author Jijoong Moon + * @author Parichay Kapoor + * @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 lgtrain(readyTrainData); \ + trainReadyFlag = val; \ + cv_train.notify_all(); \ + } break; \ + case BUF_VAL: { \ + std::lock_guard lgval(readyValData); \ + valReadyFlag = val; \ + cv_val.notify_all(); \ + } break; \ + case BUF_TEST: { \ + std::lock_guard lgtest(readyTestData); \ + testReadyFlag = val; \ + cv_test.notify_all(); \ + } break; \ + default: \ + break; \ + } \ + } while (0) diff --git a/nntrainer/meson.build b/nntrainer/meson.build index e8cc189..10e94f7 100644 --- a/nntrainer/meson.build +++ b/nntrainer/meson.build @@ -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', diff --git a/nntrainer/src/databuffer.cpp b/nntrainer/src/databuffer.cpp index 3a99ea4..7d17cdf 100644 --- a/nntrainer/src/databuffer.cpp +++ b/nntrainer/src/databuffer.cpp @@ -21,11 +21,12 @@ * */ -#include +#include #include #include #include #include +#include #include #include #include diff --git a/nntrainer/src/databuffer_file.cpp b/nntrainer/src/databuffer_file.cpp index e94d57f..5dfe216 100644 --- a/nntrainer/src/databuffer_file.cpp +++ b/nntrainer/src/databuffer_file.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -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()) { diff --git a/nntrainer/src/databuffer_func.cpp b/nntrainer/src/databuffer_func.cpp index a37c5e7..09740b3 100644 --- a/nntrainer/src/databuffer_func.cpp +++ b/nntrainer/src/databuffer_func.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -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; diff --git a/packaging/nntrainer.spec b/packaging/nntrainer.spec index aad9840..2d6aa52 100644 --- a/packaging/nntrainer.spec +++ b/packaging/nntrainer.spec @@ -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 -- 2.7.4