From 28636c90f5bfdb3a1241ad1f9cea4b589d78e584 Mon Sep 17 00:00:00 2001 From: Dongju Chae Date: Fri, 10 Apr 2020 15:09:37 +0900 Subject: [PATCH] [Svace] Fix unresolved svace issues This patch fixes unresolved svace issues. Signed-off-by: Dongju Chae --- include/common/npubinfmt.h | 24 ++++++++++++++++++++---- src/core/ne-handler.cc | 4 +++- src/core/ne-model.h | 2 +- tests/unittests/ne_core_utils_test.cc | 19 +++++++++---------- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/include/common/npubinfmt.h b/include/common/npubinfmt.h index 75e49e9..49c8927 100644 --- a/include/common/npubinfmt.h +++ b/include/common/npubinfmt.h @@ -19,12 +19,28 @@ #include #include +#include /* size of metadata */ -#define NPUBIN_META_SIZE (4096) /* unit size of metadata (minimal size) */ -#define NPUBIN_META_EXTRA(magiccode) ((uint64_t)(((magiccode) >> 8) & 0xFFULL)) /* number of extra metadata */ -#define NPUBIN_META_EXTRA_SIZE(magiccode) (NPUBIN_META_EXTRA(magiccode) * NPUBIN_META_SIZE) -#define NPUBIN_META_TOTAL_SIZE(magiccode) (NPUBIN_META_SIZE + NPUBIN_META_EXTRA_SIZE(magiccode)) + +/* unit size of metadata (minimal size) */ +#define NPUBIN_META_SIZE (4096) +/* number of extra metadata */ +#define NPUBIN_META_EXTRA(magiccode) (((magiccode) >> 8) & 0xFFULL) + +/* @brief return extra metadata size of npu binary */ +static inline uint64_t NPUBIN_META_EXTRA_SIZE (uint64_t magiccode) { + uint64_t num_extra = NPUBIN_META_EXTRA (magiccode); + assert (num_extra <= UINT8_MAX); /** sanity check for svace */ + return num_extra * NPUBIN_META_SIZE; +} + +/* @brief return total metadata size of npu binary, including extra data */ +static inline uint64_t NPUBIN_META_TOTAL_SIZE (uint64_t magiccode) { + uint64_t size_extra = NPUBIN_META_EXTRA_SIZE (magiccode); + assert (size_extra <= UINT8_MAX * NPUBIN_META_SIZE); /** sanity check for svace */ + return size_extra + NPUBIN_META_SIZE; +} /* tensor data constrains */ #define MAX_TENSORS (16) diff --git a/src/core/ne-handler.cc b/src/core/ne-handler.cc index 816887f..20c299d 100644 --- a/src/core/ne-handler.cc +++ b/src/core/ne-handler.cc @@ -617,7 +617,9 @@ Device::createInstance (dev_type type, int id) /** @brief host handler constructor */ HostHandler::HostHandler (Device *device) - : device_(device) + : device_(device), + /* ignored as we don't use double buffering anymore, but for backward-compatibility */ + async_mode_ (NPUASYNC_WAIT) { } diff --git a/src/core/ne-model.h b/src/core/ne-model.h index c5c1195..63d3723 100644 --- a/src/core/ne-model.h +++ b/src/core/ne-model.h @@ -39,7 +39,7 @@ class Metadata { public: static std::unique_ptr extractMetadata (void *data); - Metadata (npubin_meta *meta) : meta_(meta) {} + Metadata (npubin_meta *meta) : meta_(meta), version_(0) {} virtual ~Metadata () {}; virtual uint32_t getInputNum () const = 0; diff --git a/tests/unittests/ne_core_utils_test.cc b/tests/unittests/ne_core_utils_test.cc index fbd8303..a79ac88 100644 --- a/tests/unittests/ne_core_utils_test.cc +++ b/tests/unittests/ne_core_utils_test.cc @@ -127,16 +127,15 @@ TEST (ne_core_utils_test, load_conf_ini_n) /** load default configurations */ Conf & conf = Conf::getInstance (); - /** make dummy .ini file */ - FILE *fp = fopen ("dummy.ini", "w"); - const char *ini_str = "[main]\n" - "resv_mem_size=asdf\n" - "num_threads=-1\n"; - - /** from .ini file */ - ASSERT_NE (fp, nullptr); - ASSERT_EQ (fwrite (ini_str, strlen(ini_str), 1, fp), 1); - ASSERT_EQ (fclose (fp), 0); + /** make dummy .ini file (with invalid values) */ + std::ofstream ofs ("dummy.ini"); + ASSERT_EQ (ofs.good(), true); + + ofs << "[main]\n"; + ofs << "resv_mem_size=asdr\n"; + ofs << "num_threads=-1\n"; + + ofs.close(); conf = Conf::getInstance ("dummy.ini"); -- 2.7.4