/* size of metadata */
#define NPUBIN_META_SIZE (4096) /* unit size of metadata (minimal size) */
-#define NPUBIN_META_EXTRA(magiccode) ((magiccode >> 8) & 0xFFULL) /* number of extra metadata */
+#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))
typedef void *npudev_h;
/**
- * @brief Returns the list of NPU devices.
+ * @brief Returns the number of available NPU devices.
* @return @c The number of NPU devices.
* @retval 0 if no NPU devices available. if positive (number of NPUs) if NPU devices available. otherwise, a negative error value.
- */
-int getnumNPUdevice(void);
+*/
+int getnumNPUdeviceByType (dev_type type);
/**
* @brief Returns the handle of the chosen NPU devices.
* @param[out] dev The NPU device handle
- * @param[in] id The NPU id to get the handle. 0 <= id < getNumNPUDevices().
+ * @param[in] id The NPU id to get the handle. 0 <= id < getnumNPUdeviceByType().
* @return @c 0 if no error. otherwise a negative error value
+ * @note the caller should call putNPUdevice() to release the device handle
*/
-int getNPUdevice(npudev_h *dev, uint32_t id);
-
-/**
- * @brief Returns the list of ASR devices
- * @return @c The number of ASR devices.
- * @retval 0 if no ASR devices available. if positive (number of ASRs) if ASR devices available. otherwise, a negative error value.
- */
-int getnumASRdevice(void);
-
-/**
- * @brief Returns the handle of the chosen ASR device.
- * @param[out] dev The ASR device handle
- * @param[in] id The ASRi-dev id to get the handle. 0 <= id < getNumASRDevices().
- * @return @c 0 if no error. otherwise a negative error value
- */
-int getASRdevice(npudev_h *dev, uint32_t id);
+int getNPUdeviceByType (npudev_h *dev, dev_type type, uint32_t id);
/**
* @brief Description of npu device search conditions.
* @param[out] dev The NPU device handle
* @param[in] cond The condition for device search.
* @return @c 0 if no error. otherwise a negative error value
+ * @note the caller should call putNPUdevice() to release the device handle
+ * @note it's not supported yet
*/
int getNPUdeviceByCondition(npudev_h *dev, const npucondition *cond);
/**
+ * @brief release the NPU device instance obtained by getDevice ()
+ * @param[in] dev the NPU device handle
+ */
+void putNPUdevice (npudev_h dev);
+
+/**
* @brief Get metadata for NPU model
* @param[in] model The path of model binary file
* @param[in] need_extra whether you want to extract the extra data in metadata
/** deprecated buffer APIs; please use the above APIs */
+/**
+ * @deprecated
+ * @brief Returns the list of NPU devices.
+ * @return @c The number of NPU devices.
+ * @retval 0 if no NPU devices available. if positive (number of NPUs) if NPU devices available. otherwise, a negative error value.
+ */
+int getnumNPUdevice(void);
+
+/**
+ * @deprecated
+ * @brief Returns the handle of the chosen NPU devices.
+ * @param[out] dev The NPU device handle
+ * @param[in] id The NPU id to get the handle. 0 <= id < getNumNPUDevices().
+ * @return @c 0 if no error. otherwise a negative error value
+ * @note the caller should call putNPUdevice() to release the device handle
+ */
+int getNPUdevice(npudev_h *dev, uint32_t id);
+
+/**
+ * @deprecated
+ * @brief Returns the list of ASR devices
+ * @return @c The number of ASR devices.
+ * @retval 0 if no ASR devices available. if positive (number of ASRs) if ASR devices available. otherwise, a negative error value.
+ */
+int getnumASRdevice(void);
+
+/**
+ * @deprecated
+ * @brief Returns the handle of the chosen ASR device.
+ * @param[out] dev The ASR device handle
+ * @param[in] id The ASRi-dev id to get the handle. 0 <= id < getNumASRDevices().
+ * @return @c 0 if no error. otherwise a negative error value
+ * @note the caller should call putNPUdevice() to release the device handle
+ */
+int getASRdevice(npudev_h *dev, uint32_t id);
+
/** @brief deprecated */
int allocModelBuffer (generic_buffer *buffer);
/** @brief deprecated */
class TrinityVision : public Device {
public:
TrinityVision (int id) : Device (NPUCOND_TRIV_CONN_SOCIP, id) {}
+ ~TrinityVision () {}
static size_t manipulateData (const Model *model, uint32_t idx, bool is_input,
void *dst, void *src, size_t size);
class TrinityVision2 : public Device {
public:
TrinityVision2 (int id) : Device (NPUCOND_TRIV2_CONN_SOCIP, id) {}
+ ~TrinityVision2 () {}
static size_t manipulateData (const Model *model, uint32_t idx, bool is_input,
void *dst, void *src, size_t size) {
int run (npu_input_opmode opmode, const Model *model,
const input_buffers *input, npuOutputNotify cb, void *cb_data,
uint64_t *sequence) {
- if (opmode != NPUINPUT_HOST || opmode != NPUINPUT_HW_RECURRING)
+ if (opmode != NPUINPUT_HOST && opmode != NPUINPUT_HW_RECURRING)
return -EINVAL;
/** this device uses segment table */
class TrinityAsr : public Device {
public:
TrinityAsr (int id) : Device (NPUCOND_TRIA_CONN_SOCIP, id, false) {}
+ ~TrinityAsr () {}
static size_t manipulateData (const Model *model, uint32_t idx, bool is_input,
void *dst, void *src, size_t size) {
int
HostHandler::allocGenericBuffer (generic_buffer *buffer)
{
- if (buffer == NULL || SIZE_MAX < buffer->size)
+ if (buffer == NULL)
return -EINVAL;
+ if (buffer->size > UINT32_MAX) {
+ logerr (TAG, "Don't support such a large size");
+ return -ENOMEM;
+ }
+
if (buffer->type == BUFFER_FILE) {
/* nothing to do */
if (buffer->filepath == nullptr)
* @brief Returns the number of available NPU devices.
* @return @c The number of NPU devices.
* @retval 0 if no NPU devices available. if positive (number of NPUs) if NPU devices available. otherwise, a negative error value.
-*/
+ * @note the caller should call putNPUdevice() to release the device handle
+ */
int getnumNPUdeviceByType (dev_type type)
{
return HostHandler::getNumDevices (type);
}
/**
- * @brief Returns the number of NPU devices (TRIV).
- */
-int getnumNPUdevice (void)
-{
- return getnumNPUdeviceByType (NPUCOND_TRIV_CONN_SOCIP);
-}
-
-/**
- * @brief Returns the list of ASR devices (TRIA)
- */
-int getnumASRdevice (void)
-{
- return getnumNPUdeviceByType (NPUCOND_TRIA_CONN_SOCIP);
-}
-
-/**
* @brief Returns the handle of the chosen NPU devices.
* @param[out] dev The NPU device handle
* @param[in] id The NPU id to get the handle. 0 <= id < getnumNPUdeviceByType().
* @return @c 0 if no error. otherwise a negative error value
+ * @note the caller should call putNPUdevice() to release the device handle
*/
int getNPUdeviceByType (npudev_h *dev, dev_type type, uint32_t id)
{
}
/**
- * @brief Returns the handle of the chosen TRIV device.
+ * @brief Returns the handle of an NPU device meeting the condition
+ * @param[out] dev The NPU device handle
+ * @param[in] cond The condition for device search.
+ * @return @c 0 if no error. otherwise a negative error value
+ * @note the caller should call putNPUdevice() to release the device handle
+ * @note it's not supported yet
*/
-int getNPUdevice (npudev_h *dev, uint32_t id)
+int getNPUdeviceByCondition(npudev_h *dev, const npucondition *cond)
{
- return getNPUdeviceByType (dev, NPUCOND_TRIV_CONN_SOCIP, id);
+ /** not implmeneted yet */
+ return getNPUdeviceByType (dev, NPUCOND_TRIV_CONN_SOCIP, 0);
}
/**
- * @brief Returns the handle of the chosen TRIA device.
+ * @brief release the NPU device instance obtained by getDevice ()
+ * @param[in] dev the NPU device handle
*/
-int getASRdevice (npudev_h *dev, uint32_t id)
+void putNPUdevice (npudev_h dev)
{
- return getNPUdeviceByType (dev, NPUCOND_TRIA_CONN_SOCIP, id);
+ if (dev != nullptr)
+ delete static_cast<Device *> (dev);
}
/**
/** deprecated buffer APIs; please use the above APIs */
+/**
+ * @brief Returns the number of NPU devices (TRIV).
+ */
+int getnumNPUdevice (void)
+{
+ logwarn (TAG, "deprecated. Please use getnumNPUdeviceByType ()\n");
+ return getnumNPUdeviceByType (NPUCOND_TRIV_CONN_SOCIP);
+}
+
+/**
+ * @brief Returns the list of ASR devices (TRIA)
+ */
+int getnumASRdevice (void)
+{
+ logwarn (TAG, "deprecated. Please use getnumNPUdeviceByType ()\n");
+ return getnumNPUdeviceByType (NPUCOND_TRIA_CONN_SOCIP);
+}
+
+/**
+ * @brief Returns the handle of the chosen TRIV device.
+ */
+int getNPUdevice (npudev_h *dev, uint32_t id)
+{
+ logwarn (TAG, "deprecated. Please use getNPUdeviceByType ()\n");
+ return getNPUdeviceByType (dev, NPUCOND_TRIV_CONN_SOCIP, id);
+}
+
+/**
+ * @brief Returns the handle of the chosen TRIA device.
+ */
+int getASRdevice (npudev_h *dev, uint32_t id)
+{
+ logwarn (TAG, "deprecated. Please use getNPUdeviceByType ()\n");
+ return getNPUdeviceByType (dev, NPUCOND_TRIA_CONN_SOCIP, id);
+}
+
/** @brief deprecated */
int allocModelBuffer (generic_buffer *buffer)
{
/** @brief HWmem constructor */
HWmem::HWmem (const HWmemImpl* impl)
- : impl_ (impl), dmabuf_ (-1), base_addr_ (nullptr),
+ : impl_ (impl), api_ (nullptr), dmabuf_ (-1), base_addr_ (nullptr),
offset_ (0), size_ (0), parent_ (nullptr)
{
}
val *= 1024 * 1024 * 1024;
}
}
- if (val <= SIZE_MAX) {
- /** zero size is now allowed to indicate the KERNEL_CMA mode */
- reserved_mem_size_ = static_cast<size_t> (val);
- }
+
+ /** zero size is now allowed to indicate the KERNEL_CMA mode */
+ reserved_mem_size_ = static_cast<size_t> (val);
}
}
}
} else {
fprintf(stderr, "[APPTEST] %s: FAILED (%d)\n", argv[0], result);
}
- free (dev);
+ putNPUdevice (dev);
}
}
#include <fstream>
+#include "ne_unittest_utils.h"
+
/**
* @brief Test getCommPlugin()
*/
int
main (int argc, char **argv)
{
- testing::InitGoogleTest (&argc, argv);
-
- return RUN_ALL_TESTS();
+ return start_gtest (argc, argv);
}
#include <gtest/gtest.h>
#include <NPUdrvAPI.h>
+#include "ne_unittest_utils.h"
+
/**
* @brief check getNumDevices()
*/
int
main (int argc, char **argv)
{
- testing::InitGoogleTest (&argc, argv);
-
- return RUN_ALL_TESTS();
+ return start_gtest (argc, argv);
}
#include <gtest/gtest.h>
#include <ne-thread-pool.h>
+#include "ne_unittest_utils.h"
+
/**
* @brief test getInstance()
*/
int
main (int argc, char **argv)
{
- testing::InitGoogleTest (&argc, argv);
-
- return RUN_ALL_TESTS();
+ return start_gtest (argc, argv);
}
#include <gtest/gtest.h>
#include <poll.h>
-/** below are internal C-headers */
+#include <fstream>
+
#include <ne-utils.h>
#include <ne-conf.h>
+#include "ne_unittest_utils.h"
+
typedef std::vector<std::pair<const char *, char *>> ENV_PAIR;
/**
* @brief save and unset enviroment variables
save_and_unset_envvars (envvars);
/** make dummy .ini file */
- FILE *fp = fopen ("dummy.ini", "w");
- const char *ini_str = "[main]\n"
- "resv_mem_size=128k\n"
- "num_threads=4\n"
- "log_dir=/tmp/test_log\n";
+ std::ofstream ofs ("dummy.ini");
+ ASSERT_EQ (ofs.good(), true);
- /** from .ini file */
- ASSERT_NE (fp, nullptr);
- ASSERT_EQ (fwrite (ini_str, strlen(ini_str), 1, fp), 1);
- ASSERT_EQ (fclose (fp), 0);
+ ofs << "[main]\n";
+ ofs << "resv_mem_size=128k\n";
+ ofs << "num_threads=4\n";
+ ofs << "log_dir=/tmp/test_log\n";
+
+ ofs.close();
Conf & conf = Conf::getInstance ("dummy.ini");
int
main (int argc, char **argv)
{
- testing::InitGoogleTest (&argc, argv);
-
- return RUN_ALL_TESTS();
+ return start_gtest (argc, argv);
}
--- /dev/null
+/**
+ * Proprietary
+ * Copyright (C) 2020 Samsung Electronics
+ * Copyright (C) 2020 Dongju Chae <dongju.chae@samsung.com>
+ */
+/**
+ * @file ne_unittest_utils.h
+ * @date 09 Apr 2020
+ * @brief Utility header for UnitTests
+ * @author Dongju Chae <dongju.chae@samsung.com>
+ */
+
+#ifndef _NE_UNITTEST_UTILS_H_
+#define _NE_UNITTEST_UTILS_H_
+
+#include <gtest/gtest.h>
+
+/**
+ * @brief start gtest with tricky exception handling (due to svace)
+ */
+inline int start_gtest (int argc, char **argv) {
+ int ret = -1;
+ try {
+ testing::InitGoogleTest (&argc, argv);
+ } catch (...) {
+ std::cerr << "catch 'testing::internal::<unnamed>::ClassUniqueToAlwaysTrue'" << std::endl;
+ }
+ try {
+ ret = RUN_ALL_TESTS();
+ } catch (...) {
+ std::cerr << "catch `testing::internal::GoogleTestFailureException`" << std::endl;
+ }
+ return ret;
+}
+
+#endif /* _NE_UNITTEST_UTILS_H_ */
}
closedir(d);
- free (dev);
+ putNPUdevice (dev);
fprintf(stderr, "[APPTEST] %s: %s (%d/%d)\n",
name, total_fails == 0 ? "PASSED" : "FAILED",