/** alias */
#define DEVICETYPE_TRIV DEVICETYPE_NPU
#define DEVICETYPE_TRIA DEVICETYPE_ASR
-#define DEVICETYPE_TRIV2 (0x30000) /** SR-NPU 2020 */
+#define DEVICETYPE_TRIV2 (0x30000) /** VD/SR-NPU 2020 */
#define DEVICETYPE_MASK (0xFFFF0000)
* Wook Song <wook16.song@samsung.com>
* Parichay Kapoor <pk.kapoor@samsung.com>
* @bug No known bugs except for NYI items
+ * @note libnpuhost.h is the entry point to access NPU Engine (by host handler).
+ * Also, the term 'NPU' now includes all variants such as traditional NPU, ASR,
+ * and new device types (i.e., TRIV, TRIV2, and TRIA).
*/
#ifndef __NPU_HOST_LIBNPUHOST_H__
#include <typedef.h>
#include <npubinfmt.h>
-/**
- * Note that libnpuhost is the entry point to access NPU Engine (by host handler).
- * Also, the term 'NPU' now includes all variants such as traditional NPU, ASR,
- * and new device types (i.e., TRIV, TRIV2, and TRIA). Existing APIs that do not
- * specify a device type in their names (e.g., getNPUdevice/getASRdevice) are now
- * deprecated (but still supported).
- */
-
#if defined(__cplusplus)
extern "C" {
#endif
int getNPUdeviceByType (npudev_h *dev, dev_type type, uint32_t id);
/**
- * @brief Description of npu device search conditions.
- * @todo this feature is not supported yet
- */
-typedef struct {
- dev_type connection; /**< Desginates NPU connection types. Use NPUCOND_CONN_UNKNOWN to say "I don't care." */
-
- enum {
- NPUCOND_SORT_ANY = 0, /**< Choose any. Don't care ID num */
- NPUCOND_SORT_MIN_ID = 1, /**< Choose smaller device ID */
- NPUCOND_SORT_MAX_ID = 2, /**< Choose larger device ID */
- } sort; /**< Choose based on device id number */
-
- enum {
- NPUCOND_LOAD_ANY = 0, /**< Does not care how many models are loaded */
- NPUCOND_LOAD_NO = 1, /**< Choose a device without any models loaded */
- NPUCOND_LOAD_MIN_MODEL = 2, /**< Choose a device with least models loaded */
- NPUCOND_LOAD_MAX_MEMORY = 3, /**< Choose a device with the most free memory available */
- } loads; /**< Choose based on device resource status */
-} npucondition;
-
-/**
- * @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
- * @todo this feature is 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
*/
*/
int getNPU_memoryStatus(npudev_h dev, size_t *alloc_total, size_t *free_total);
-/** Optional Features. May be left unimplemented until later versions */
-/** @todo func prototype TBD. This does not use callback. */
-int runNPU_async_noalloc(npudev_h dev, uint32_t modelid, const input_buffers *input,
- output_buffers *output, uint64_t *sequence, npu_async_mode mode);
-
-/** @todo func prototype TBD */
-int getRegisteredNPUmodels(npudev_h dev, uint32_t **modelids, uint32_t *nummodels);
-
-/** @todo func prototype TBD */
-int waitNPUrun(npudev_h dev);
-
-/** @todo func prototype TBD */
-int getNPUrunStatus(npudev_h dev, uint64_t *status);
-
-/** @todo func prototype TBD */
-int getNPUstatus(npudev_h dev, uint64_t *status);
-
/**
* [IMPORTANT] Descriptions for buffer allocation APIs.
*
*/
int cleanNPU_inputBuffers (npudev_h dev, input_buffers * input);
-/** 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.
+ * Optional Features. May be left unimplemented until later versions
*/
-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);
+/** @todo func prototype TBD. This does not use callback. */
+int runNPU_async_noalloc(npudev_h dev, uint32_t modelid, const input_buffers *input,
+ output_buffers *output, uint64_t *sequence, npu_async_mode mode);
-/**
- * @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);
+/** @todo func prototype TBD */
+int getRegisteredNPUmodels(npudev_h dev, uint32_t **modelids, uint32_t *nummodels);
-/**
- * @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);
-
-/** @deprecated */
-int allocModelBuffer (generic_buffer *buffer);
-/** @deprecated */
-int cleanModelBuffer (generic_buffer *buffer);
-/** @deprecated */
-int allocInputBuffer (generic_buffer *buffer);
-/** @deprecated */
-int cleanInputBuffer (generic_buffer *buffer);
-/** @deprecated */
-int allocInputBuffers (input_buffers * input);
-/** @deprecated */
-int cleanInputBuffers (input_buffers * input);
-/** @deprecated */
-int allocNPUBuffer (uint64_t size, buffer_types type,
- const char * filepath, generic_buffer *buffer);
-/** @deprecated */
-int cleanNPUBuffer (generic_buffer * buffer);
+/** @todo func prototype TBD */
+int waitNPUrun(npudev_h dev);
+
+/** @todo func prototype TBD */
+int getNPUrunStatus(npudev_h dev, uint64_t *status);
+
+/** @todo func prototype TBD */
+int getNPUstatus(npudev_h dev, uint64_t *status);
#if defined(__cplusplus)
}
%endif
done
- # Run example_visa with sample models
+ # Run example_visa with a few sample models (due to performance issues)
mkdir -p sample_models_v1
mkdir -p sample_models_v2
mkdir -p sample_models_v3
pushd build
- # Collect coverage statistics using gcovr
+ # Collect coverage statistics using gcovr (excluding some files used only in FastModel)
gcovr -r .. --html --html-details \
--html-title "NPU SystemService Coverage" \
--filter ../src/ --filter ../include/ \
+ --exclude ../src/core/npu/NPUdrvAPI_triv.cc \
+ --exclude ../src/core/npu/NPUdrvAPI_triv2.cc \
+ --exclude ../src/core/npu/NPUdrvAPI_tria.cc \
-o index.html
# Copy the coverage results
}
/**
- * @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 getNPUdeviceByCondition(npudev_h *dev, const npucondition *cond)
-{
- /** not implmeneted yet */
- return getNPUdeviceByType (dev, NPUCOND_TRIV_CONN_SOCIP, 0);
-}
-
-/**
* @brief release the NPU device instance obtained by getDevice ()
* @param[in] dev the NPU device handle
*/
return nullptr;
}
-/** 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)
-{
- logwarn (TAG, "deprecated. Please use allocNPU_modelBuffer\n");
- return allocNPU_modelBuffer (HostHandler::getLatestDevice(), buffer);
-}
-
-/** @brief deprecated */
-int cleanModelBuffer (generic_buffer *buffer)
-{
- logwarn (TAG, "deprecated. Please use cleanNPU_modelBuffer\n");
- return allocNPU_modelBuffer (HostHandler::getLatestDevice(), buffer);
-}
-
-/** @brief deprecated */
-int allocInputBuffer (generic_buffer *buffer)
-{
- logwarn (TAG, "deprecated. Please use allocNPU_inputBuffer\n");
- return allocNPU_inputBuffer (HostHandler::getLatestDevice(), buffer);
-}
-
-/** @brief deprecated */
-int cleanInputBuffer (generic_buffer *buffer)
-{
- logwarn (TAG, "deprecated. Please use cleanNPU_inputBuffer\n");
- return cleanNPU_inputBuffer (HostHandler::getLatestDevice(), buffer);
-}
-
-/** @brief deprecated */
-int allocInputBuffers (input_buffers * input)
-{
- logwarn (TAG, "deprecated. Please use allocNPU_inputBuffers\n");
- return allocNPU_inputBuffers (HostHandler::getLatestDevice(), input);
-}
-
-/** @brief deprecated */
-int cleanInputBuffers (input_buffers * input)
-{
- logwarn (TAG, "deprecated. Please use cleanNPU_inputBuffers\n");
- return cleanNPU_inputBuffers (HostHandler::getLatestDevice(), input);
-}
-
-/** @brief deprecated */
-int allocNPUBuffer (uint64_t size, buffer_types type,
- const char * filepath, generic_buffer *buffer)
-{
- if (buffer) {
- buffer->size = size;
- buffer->type = type;
- buffer->filepath = filepath;
- }
-
- logwarn (TAG, "deprecated. Please use allocNPU_* APIs\n");
- return allocModelBuffer (buffer);
-}
-
-/** @brief deprecated */
-int cleanNPUBuffer (generic_buffer * buffer)
-{
- logwarn (TAG, "deprecated. Please use cleanNPU_* APIs\n");
- return cleanModelBuffer (buffer);
-}
-
/** implement methods of HostHandler class */
/** @brief host handler constructor */
/** The below requires initialized device */
/** @brief check whether the device is ready (true) or busy (false) */
- virtual device_state_t isReady () const { return device_state_t::STATE_END; }
+ virtual device_state_t isReady () const { return device_state_t::STATE_UNKNOWN; }
/** @brief allocate memory with the given size. return dmabuf fd */
virtual int alloc (size_t size) const { return -EPERM; }
int
main (int argc, char **argv)
{
- npudev_h dev;
- int num_devices = getnumNPUdevice();
+ int num_devices = getnumNPUdeviceByType (NPUCOND_TRIV_CONN_SOCIP);
int result = -1;
+ npudev_h dev;
if (num_devices) {
- if (getNPUdevice (&dev, num_devices - 1) == 0) {
+ if (getNPUdeviceByType (&dev, NPUCOND_TRIV_CONN_SOCIP, num_devices - 1) == 0) {
result = run_inference (dev);
if (result == 0)
fprintf(stderr, "[APPTEST] %s: PASSED\n", argv[0]);
int
main (int argc, char **argv)
{
- npudev_h dev;
- int num_devices = getnumNPUdevice();
+ int num_devices = getnumNPUdeviceByType (NPUCOND_TRIV_CONN_SOCIP);
int result = -1;
+ npudev_h dev;
if (num_devices) {
- if (getNPUdevice (&dev, num_devices - 1) == 0) {
+ if (getNPUdeviceByType (&dev, NPUCOND_TRIV_CONN_SOCIP, num_devices - 1) == 0) {
result = run_inference (dev);
if (result == 0) {
fprintf(stderr, "[APPTEST] %s: PASSED\n", argv[0]);
const size_t size = 4096;
model_config_t model;
input_config_t input;
+ size_t alloc, free;
/** create driver APIs not using createDriverAPI() */
std::unique_ptr<DriverAPI> api (new TrinityVisionAPI (0));
- /** TODO unimplemented yet */
EXPECT_NE (api->open (), 0);
- EXPECT_EQ (api->isReady (), -EPERM);
+ EXPECT_EQ (api->isReady (), device_state_t::STATE_UNKNOWN);
EXPECT_EQ (api->alloc (size), -EPERM);
EXPECT_EQ (api->dealloc (0), -EPERM);
EXPECT_EQ (api->mmap (0, size), nullptr);
EXPECT_EQ (api->munmap (nullptr, size), -EPERM);
EXPECT_EQ (api->registerModel (&model), -EPERM);
+ EXPECT_EQ (api->deregisterModel (0), -EPERM);
+ EXPECT_EQ (api->getMemoryStatus (&alloc, &free), -EPERM);
EXPECT_EQ (api->runInput (&input), -EPERM);
api.reset (new TrinityVision2API (0));
- /** @todo unimplemented yet */
EXPECT_NE (api->open (), 0);
- EXPECT_EQ (api->isReady (), -EPERM);
+ EXPECT_EQ (api->isReady (), device_state_t::STATE_UNKNOWN);
EXPECT_EQ (api->alloc (size), -EPERM);
EXPECT_EQ (api->dealloc (0), -EPERM);
EXPECT_EQ (api->mmap (0, size), nullptr);
EXPECT_EQ (api->munmap (nullptr, size), -EPERM);
EXPECT_EQ (api->registerModel (&model), -EPERM);
+ EXPECT_EQ (api->deregisterModel (0), -EPERM);
+ EXPECT_EQ (api->getMemoryStatus (&alloc, &free), -EPERM);
EXPECT_EQ (api->runInput (&input), -EPERM);
-#if 0
api.reset (new TrinityAsrAPI (0));
- /** TODO unimplemented yet */
EXPECT_NE (api->open (), 0);
- EXPECT_EQ (api->isReady (), -EPERM);
+ EXPECT_EQ (api->isReady (), device_state_t::STATE_UNKNOWN);
EXPECT_EQ (api->alloc (size), -EPERM);
EXPECT_EQ (api->dealloc (0), -EPERM);
EXPECT_EQ (api->mmap (0, size), nullptr);
EXPECT_EQ (api->munmap (nullptr, size), -EPERM);
EXPECT_EQ (api->registerModel (&model), -EPERM);
+ EXPECT_EQ (api->deregisterModel (0), -EPERM);
+ EXPECT_EQ (api->getMemoryStatus (&alloc, &free), -EPERM);
EXPECT_EQ (api->runInput (&input), -EPERM);
-#endif
#ifdef ENABLE_EMUL
api.reset (new TrinityEmulAPI (0, NPUCOND_TRIV_CONN_SOCIP));
EXPECT_NE (api->open (), 0);
/** but, not initialized */
- EXPECT_EQ (api->isReady (), -EPERM);
+ EXPECT_EQ (api->isReady (), device_state_t::STATE_UNKNOWN);
EXPECT_EQ (api->alloc (size), -EPERM);
EXPECT_EQ (api->dealloc (0), -EPERM);
EXPECT_EQ (api->mmap (0, size), nullptr);
EXPECT_EQ (api->munmap (nullptr, size), -EPERM);
EXPECT_EQ (api->registerModel (&model), -EPERM);
+ EXPECT_EQ (api->deregisterModel (0), -EPERM);
+ EXPECT_EQ (api->getMemoryStatus (&alloc, &free), -EPERM);
EXPECT_EQ (api->runInput (&input), -EPERM);
api.reset (new TrinityEmulAPI (0, NPUCOND_TRIV2_CONN_SOCIP));
EXPECT_NE (api->open (), 0);
/** but, not initialized */
- EXPECT_EQ (api->isReady (), -EPERM);
+ EXPECT_EQ (api->isReady (), device_state_t::STATE_UNKNOWN);
EXPECT_EQ (api->alloc (size), -EPERM);
EXPECT_EQ (api->dealloc (0), -EPERM);
EXPECT_EQ (api->mmap (0, size), nullptr);
EXPECT_EQ (api->munmap (nullptr, size), -EPERM);
EXPECT_EQ (api->registerModel (&model), -EPERM);
+ EXPECT_EQ (api->deregisterModel (0), -EPERM);
+ EXPECT_EQ (api->getMemoryStatus (&alloc, &free), -EPERM);
EXPECT_EQ (api->runInput (&input), -EPERM);
#endif
}