This patch removes some testcases for TRIV1.
The kernel driver does not support TRIV1 anymore.
Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
#include <stdint.h>
-#define DEVICETYPE_NPU (0x10000) /** SR-NPU 2019, RefineDet */
-#define DEVICETYPE_ASR (0x20000) /** SR-ASR-IP 2019, Based on SRP */
+/** Deprecated devices */
+#define DEVICETYPE_DEPR (0x10000)
+#define DEVICETYPE_ASR DEVICETYPE_DEPR
+#define DEVICETYPE_TRIV DEVICETYPE_DEPR
+#define DEVICETYPE_TRIA DEVICETYPE_DEPR
-/** alias */
-#define DEVICETYPE_TRIV DEVICETYPE_NPU
-#define DEVICETYPE_TRIA DEVICETYPE_ASR
-#define DEVICETYPE_TRIV2 (0x40000) /** VD/SR-NPU 2020 */
-
-#define DEVICETYPE_MASK (0xFFFF0000)
+#define DEVICETYPE_TRIV2 (0x40000) /** VD/SR-NPU 2020 */
+/** TODO: there will be other device variants */
+#define DEVICETYPE_MASK (0xFFFF0000)
/**
* @brief Represents an "opened" single NPU device (e.g., TRIV2).
* @brief Description of npu device types.
*/
typedef enum {
- NPUCOND_CONN_UNKNOWN = (DEVICETYPE_NPU | 0), /**< ERROR or "Don't Care" */
- NPUCOND_CONN_USB = (DEVICETYPE_NPU | 1), /**< USB type only! */
- NPUCOND_CONN_SOCIP = (DEVICETYPE_NPU | 2), /**< SOCIP type only! */
- NPUCOND_CONN_PCIE = (DEVICETYPE_NPU | 3), /**< PCI-express type only! */
- NPUCOND_CONN_FILESYS = (DEVICETYPE_NPU | 4), /**< Connected via file systems (for testing purpose) */
-
- NPUCOND_ASR_CONN_UNKNOWN = (DEVICETYPE_ASR | 0), /**< As long as it is ASR(Audio-SRP), I don't care */
- NPUCOND_ASR_CONN_SOCIP = (DEVICETYPE_ASR | 2), /**< SOCIP type ASR(Audio-SRP) */
-
- NPUCOND_TRIV_CONN_UNKNOWN = (DEVICETYPE_TRIV | 0),
- NPUCOND_TRIV_CONN_SOCIP = (DEVICETYPE_TRIV | 2),
-
+ NPUCOND_CONN_UNKNOWN = DEVICETYPE_TRIV2,
+ /* TRIV2 */
NPUCOND_TRIV2_CONN_UNKNOWN = (DEVICETYPE_TRIV2 | 0),
NPUCOND_TRIV2_CONN_SOCIP = (DEVICETYPE_TRIV2 | 2),
-
+ /* deprecated */
+ NPUCOND_TRIV_CONN_UNKNOWN = (DEVICETYPE_TRIV | 0),
+ NPUCOND_TRIV_CONN_SOCIP = (DEVICETYPE_TRIV | 2),
NPUCOND_TRIA_CONN_UNKNOWN = (DEVICETYPE_TRIA | 0),
NPUCOND_TRIA_CONN_SOCIP = (DEVICETYPE_TRIA | 2),
} dev_type;
return output_[idx].get();
return nullptr;
}
-
Device *device = nullptr;
switch (type & DEVICETYPE_MASK) {
- case DEVICETYPE_TRIV:
- device = new TrinityVision (id);
- break;
case DEVICETYPE_TRIV2:
device = new TrinityVision2 (id);
break;
- case DEVICETYPE_TRIA:
- device = new TrinityAsr (id);
- device->setNeedModel (false);
+ case DEVICETYPE_DEPR:
+ logwarn (TAG, "You're trying to open deprecated devices..\n");
break;
default:
break;
}
/**
- * @brief extract the buffer instance from input generic buffers
- * @param[in] meta the model metadata
- * @param[in] input the input generic buffers
- * @return the buffer instance
- */
-Buffer *
-TrinityVision::prepareInputBuffers (const Metadata *meta, const input_buffers *input)
-{
- if (meta == nullptr || input == nullptr ||
- meta->getInputNum() != input->num_buffers) {
- logerr (TAG, "Invalid metadata info provided\n");
- return nullptr;
- }
-
- Buffer * buffer;
- const generic_buffer *first = &input->bufs[0];
- if (first->type == BUFFER_DMABUF) {
- buffer = mem_->allocBuffer (new HWmemExternal);
- if (buffer == nullptr)
- return nullptr;
-
- buffer->setDmabuf (first->dmabuf);
- buffer->setOffset (first->offset);
- buffer->setSize (meta->getBufferSize());
- } else {
- buffer = mem_->allocBuffer (new HWmemDevice);
- if (buffer == nullptr)
- return nullptr;
-
- int status = buffer->alloc (meta->getBufferSize ());
- if (status != 0) {
- logerr (TAG, "Failed to allocate buffer: %d\n", status);
- delete buffer;
- return nullptr;
- }
- }
-
- int status = buffer->createTensors (meta);
- if (status != 0) {
- logerr (TAG, "Failed to create tensors: %d\n", status);
- delete buffer;
- buffer = nullptr;
- }
-
- return buffer;
-}
-
-/**
- * @brief implementation of TRIV's setModel ()
- * @param[in] model_buf the model generic buffer
- * @param[out] model the model instance
- * @return 0 if no error, otherwise a negative errno
- */
-int
-TrinityVision::setModel (const generic_buffer *model_buf, Model ** model_ptr)
-{
- if (!initialized ()) {
- logerr (TAG, "Uninitialized device; should use libnpuhost APIs\n");
- return -EPERM;
- }
-
- if (model_buf == nullptr || model_ptr == nullptr)
- return -EINVAL;
-
- Model *model = nullptr;
- HWmem * hwmem_prog = nullptr;
- HWmem * hwmem_weight = nullptr;
- int status;
-
- /** In TRIV1, model data (including program/weight) should be contiguous */
-
- switch (model_buf->type) {
- case BUFFER_FILE:
- case BUFFER_MAPPED:
- model = mem_->allocModel (new HWmemDevice);
- if (model == nullptr) {
- logerr (TAG, "Failed to allocate model\n");
- return -ENOMEM;
- }
-
- status = model->alloc (model_buf->size);
- if (status != 0) {
- logerr (TAG, "Failed to allocate model: %d\n", status);
- goto delete_exit;
- }
-
- /** extract the whole model data */
- status = comm_.extractGenericBuffer (model_buf, model->getData(), nullptr);
- if (status != 0) {
- logerr (TAG, "Failed to extract generic buffer: %d\n", status);
- goto delete_exit;
- }
- break;
- default:
- return -EINVAL;
- }
-
- status = model->setMetadata (model->getData());
- if (status != 0)
- goto delete_exit;
-
- /** allocate program (optional; NOP) */
- if (model->getMetadata()->getProgramSize() > 0) {
- hwmem_prog = new HWmem (new HWmemChunk);
- model->setProgramData (hwmem_prog);
-
- hwmem_prog->setParent (model);
- hwmem_prog->setOffset (model->getMetadata()->getMetaSize());
- status = hwmem_prog->alloc (model->getMetadata()->getProgramSize());
- if (status != 0) {
- logerr (TAG, "Failed to allocate program\n");
- goto delete_exit;
- }
- }
-
- /** allocate weight (optional) */
- if (model->getMetadata()->getWeightSize() > 0) {
- hwmem_weight = new HWmem (new HWmemChunk);
- model->setWeightData (hwmem_weight);
-
- hwmem_weight->setParent (model);
- hwmem_weight->setOffset (model->getMetadata()->getMetaSize() +
- model->getMetadata()->getProgramSize());
- status = hwmem_weight->alloc (model->getMetadata()->getWeightSize());
- if (status != 0) {
- logerr (TAG, "Failed to allocate program\n");
- goto delete_exit;
- }
- }
-
- if (hwmem_prog != nullptr) {
- /** register this model to the driver */
- model_config_t config;
- config.version = model->getMetadata()->getVersion ();
- config.dbuf_fd = hwmem_prog->getDmabuf ();
- config.program_size = hwmem_prog->getSize ();
- config.program_offset_addr = hwmem_prog->getOffset ();
- if (hwmem_weight != nullptr)
- config.weight_offset_addr = hwmem_weight->getOffset ();
-
- status = api_->registerModel (&config);
- if (status != 0)
- goto delete_exit;
-
- model->setInternalID(config.id);
- }
-
- *model_ptr = model;
- return status;
-
-delete_exit:
- delete model;
- return status;
-}
-
-/**
- * @brief implementation of TRIV's unsetModel ()
- * @param[in] model the model instance
- * @return 0 if no error, otherwise a negative errno
- */
-int
-TrinityVision::unsetModel (Model * model)
-{
- if (!initialized ()) {
- logerr (TAG, "Uninitialized device; should use libnpuhost APIs\n");
- return -EPERM;
- }
-
- if (model == nullptr) {
- logerr (TAG, "Invalid model instance\n");
- return -EINVAL;
- }
-
- if (model->getMetadata()->getProgramSize() > 0)
- return api_->deregisterModel (model->getInternalID ());
-
- return 0;
-}
-
-/**
- * @brief implementation of TRIV's run()
- * @param[in] opmode input opmode
- * @param[in] model the model instance
- * @param[in] input generic buffers of input data
- * @param[in] cb the output callback
- * @param[in] cb_data the output callback data
- * @param[out] sequence The sequence number returned with runNPU_async.
- */
-int
-TrinityVision::run (npu_input_opmode opmode, const Model *model,
- const input_buffers *input, npuOutputNotify cb, void *cb_data,
- uint64_t *sequence)
-{
- if (!initialized ()) {
- logerr (TAG, "Uninitialized device; should use libnpuhost APIs\n");
- return -EPERM;
- }
-
- if (opmode != NPUINPUT_HOST) {
- logerr (TAG, "TRIV supports only host inputservice\n");
- return -EINVAL;
- }
-
- if (model == nullptr || input == nullptr) {
- logerr (TAG, "TRIV requires both model and input buffers\n");
- return -EINVAL;
- }
-
- const_cast<Model *>(model)->updateDataInfo ();
-
- Buffer *buffer = prepareInputBuffers (model->getMetadata(), input);
- if (buffer == nullptr) {
- logerr (TAG, "Failed to extract buffer instance\n");
- return -EINVAL;
- }
-
- if (!buffer->isExternal ()) {
- for (uint32_t idx = 0; idx < input->num_buffers; idx++) {
- auto func = std::bind (TrinityVision::manipulateData, model, idx, true,
- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
- int status = comm_.extractGenericBuffer (&input->bufs[idx],
- buffer->getInputTensor(idx)->getData(), func);
- if (status != 0) {
- logerr (TAG, "Failed to feed input buffer: %d\n", status);
- return status;
- }
- }
- }
-
- /** this device uses CMA buffer */
-
- Request *req = new Request (opmode);
- req->setModel (model);
- req->setBuffer (buffer);
-
- if (cb != nullptr)
- req->setCallback (std::bind (&TrinityVision::callback, this, req, cb, cb_data));
-
- if (sequence != nullptr)
- *sequence = req->getID();
-
- return scheduler_->submitRequest (req);
-}
-
-/**
- * @brief callback of TRIV2 request
- * @param[in] req the request instance
- * @param[in] cb callback for completion
- * @param[in] cb_data callback data
- * @note The callback invoke does not gurantee the request was successful
- * @todo Check the request failures
- */
-void
-TrinityVision::callback (Request *req, npuOutputNotify cb, void *cb_data)
-{
- const Model *model = req->getModel ();
- Buffer *buffer = req->getBuffer ();
- output_buffers output = {
- .num_buffers = buffer->getOutputNum ()
- };
-
- for (uint32_t idx = 0; idx < output.num_buffers; idx++) {
- uint32_t output_tensor_size = model->getOutputTensorSize (idx);
-
- if (buffer->isExternal ()) {
- output.bufs[idx].type = BUFFER_DMABUF;
- output.bufs[idx].size = output_tensor_size;
- output.bufs[idx].addr = buffer->getOutputTensor(idx)->getData();
- } else {
- output.bufs[idx].type = BUFFER_MAPPED;
- output.bufs[idx].size = output_tensor_size;
- /** user needs to free this */
- output.bufs[idx].addr = malloc (output_tensor_size);
-
- auto func = std::bind (TrinityVision::manipulateData, model, idx, false,
- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
- int status = comm_.insertGenericBuffer (buffer->getOutputTensor(idx)->getData(),
- &output.bufs[idx], func);
- if (status != 0) {
- logerr (TAG, "Failed to return output buffer: %d\n", status);
- }
- }
- }
-
- cb (&output, req->getID(), cb_data);
-
- delete buffer;
-}
-
-/**
* @brief extract the segment table instance from input generic buffers
* @param[in] model the model instance
* @param[in] input the input generic buffers
void
TrinityVision2::callback (Request *req, npuOutputNotify cb, void *cb_data)
{
+ if (cb == nullptr)
+ return;
+
const Model *model = req->getModel ();
SegmentTable *segt = req->getSegmentTable ();
output_buffers output = {
delete segt;
}
-/** @brief implementation of TRIA's run(): WIP */
-int
-TrinityAsr::run (npu_input_opmode opmode, const Model *model,
- const input_buffers *input, npuOutputNotify cb, void *cb_data,
- uint64_t *sequence)
-{
- if (!initialized ()) {
- logerr (TAG, "Uninitialized device; should use libnpuhost APIs\n");
- return -EPERM;
- }
-
- if (opmode != NPUINPUT_HOST)
- return -EINVAL;
-
- if (input == nullptr || input->num_buffers != 1)
- return -EINVAL;
-
- Buffer * buffer;
- int status;
- /** ASR does not require model and support only a single tensor */
- const generic_buffer *first_buf = &input->bufs[0];
- if (first_buf->type == BUFFER_DMABUF) {
- buffer = mem_->allocBuffer (new HWmemExternal);
- if (buffer == nullptr)
- return -ENOMEM;
-
- buffer->setDmabuf (first_buf->dmabuf);
- buffer->setOffset (first_buf->offset);
- buffer->setSize (first_buf->size);
- } else {
- buffer = mem_->allocBuffer (new HWmemDevice);
- if (buffer == nullptr)
- return -ENOMEM;
-
- status = buffer->alloc (first_buf->size);
- if (status != 0) {
- delete buffer;
- return status;
- }
- }
-
- status = buffer->createTensors ();
- if (status != 0) {
- logerr (TAG, "Failed to create tensors: %d\n", status);
- delete buffer;
- return status;
- }
-
- if (!buffer->isExternal ()) {
- status = comm_.extractGenericBuffer (first_buf,
- buffer->getInputTensor(0)->getData(), nullptr);
- if (status != 0)
- return status;
- }
-
- Request *req = new Request (opmode);
- req->setBuffer (buffer);
- req->setCallback (std::bind (&TrinityAsr::callback, this, req, cb, cb_data));
-
- if (sequence)
- *sequence = req->getID();
-
- return scheduler_->submitRequest (req);
-}
-
-/** @brief callback of TRIA request: WIP */
-void
-TrinityAsr::callback (Request *req, npuOutputNotify cb, void *cb_data)
-{
- Buffer *buffer = req->getBuffer ();
- output_buffers output = {
- .num_buffers = 0
- };
-
- /** TODO: finalize this impl. when the ASR's working scenario is determined */
- cb (&output, req->getID(), cb_data);
-
- delete buffer;
-}
-
/** Implement data manipulation (each device may have different impl.) */
#ifdef ENABLE_MANIP
-
-/**
- * @brief perform data manipulation
- * @param[in] model model instance
- * @param[in] idx tensor index
- * @param[in] is_input indicate it's input manipulation
- * @param[out] dst destination buffer
- * @param[in] src source buffer (feature map)
- * @param[in] size size to be copied
- * @return size of memory copy if no error, otherwise zero
- *
- * @note the input data format should be NHWC
- * @detail rules for the memory address of activations in NPU HW.
- * (https://code.sec.samsung.net/confluence/pages/viewpage.action?pageId=146491864)
- *
- * 1) Special case (depth == 3)
- * - addr(x,y,z) = addr(0,0,0) + (z) + 3 * (x + width * y)
- *
- * 2) Common case
- * - addr(x,y,z) = addr(0,0,0) + (z % MPA_L) + MPA_L * (x + width * (y + height * (z / MPA_L)))
- *
- * Thus, if depth is not a multiple of MPA_L (i.e., 64), zero padding is required
- */
-size_t
-TrinityVision::manipulateData (const Model *model, uint32_t idx, bool is_input,
- void *dst, void *src, size_t size)
-{
- const Metadata *meta = model->getMetadata();
- DataConverter converter (is_input);
-
- converter.setData (src, dst, size);
-
- if (is_input) {
- const tensor_data_info* info = model->getInputDataInfo (idx);
- if (info == nullptr)
- return 0;
-
- converter.setDataLayout (info->layout, DATA_LAYOUT_SRNPU);
- converter.setDataType (info->type, DATA_TYPE_SRNPU);
- converter.setDataDims (meta->getInputDims (idx));
- converter.setQuantZero (meta->getInputQuantZero (idx));
- converter.setQuantScale (meta->getInputQuantScale (idx));
- } else {
- const tensor_data_info* info = model->getOutputDataInfo (idx);
- if (info == nullptr)
- return 0;
-
- converter.setDataLayout (DATA_LAYOUT_SRNPU, info->layout);
- converter.setDataType (DATA_TYPE_SRNPU, info->type);
- converter.setDataDims (meta->getOutputDims (idx));
- converter.setQuantZero (meta->getOutputQuantZero (idx));
- converter.setQuantScale (meta->getOutputQuantScale (idx));
- }
-
- return converter.perform ();
-}
-
/**
* @brief perform data manipulation
* @param[in] model model instance
#else
size_t
-TrinityVision::manipulateData (const Model *model, uint32_t idx, bool is_input,
- void *dst, void *src, size_t size)
-{
- memcpy (dst, src, size);
- return size;
-}
-
-size_t
TrinityVision2::manipulateData (const Model *model, uint32_t idx, bool is_input,
void *dst, void *src, size_t size)
{
}
#endif
-
-/** other device types don't have data manip impl. yet */
-
-size_t
-TrinityAsr::manipulateData (const Model *model, uint32_t idx, bool is_input,
- void *dst, void *src, size_t size)
-{
- memcpy (dst, src, size);
- return size;
-}
std::atomic_flag atomic_flag_; /**< atomic flag to check initilization */
};
-/** @brief Trinity Vision (TRIV) classs */
-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);
-
- Buffer * prepareInputBuffers (const Metadata *meta, const input_buffers *input);
-
- int setModel (const generic_buffer *model, Model ** model_ptr);
- int unsetModel (Model * model);
- int run (npu_input_opmode opmode, const Model *model,
- const input_buffers *input, npuOutputNotify cb = nullptr,
- void *cb_data = nullptr, uint64_t *sequence = nullptr);
-
- private:
- void callback (Request *req, npuOutputNotify cb, void *cb_data);
-};
-
-/** @brief Trinity Vision2 (TRIV2) class, WIP */
+/** @brief Trinity Vision2 (TRIV2) class */
class TrinityVision2 : public Device {
public:
TrinityVision2 (int id) : Device (NPUCOND_TRIV2_CONN_SOCIP, id) {}
private:
void callback (Request *req, npuOutputNotify cb, void *cb_data);
};
-
-/** @brief Trinity Asr (TRIA) class, WIP */
-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 run (npu_input_opmode opmode, const Model *model,
- const input_buffers *input, npuOutputNotify cb = nullptr,
- void *cb_data = nullptr, uint64_t *sequence = nullptr);
-
- private:
- void callback (Request *req, npuOutputNotify cb, void *cb_data);
-};
#endif /* __NPU_ENGINE_HANDLER_H__ */
DriverAPI::getNumDevices (dev_type type)
{
switch (type & DEVICETYPE_MASK) {
-#ifdef ENABLE_EMUL
- case DEVICETYPE_TRIA:
- case DEVICETYPE_TRIV:
case DEVICETYPE_TRIV2:
+#ifdef ENABLE_EMUL
return TrinityEmulAPI::getNumDevices ();
#else
- case DEVICETYPE_TRIA:
- return TrinityAsrAPI::getNumDevices ();
- case DEVICETYPE_TRIV:
- return TrinityVisionAPI::getNumDevices ();
- case DEVICETYPE_TRIV2:
return TrinityVision2API::getNumDevices ();
#endif
default:
DriverAPI * api = nullptr;
switch (type & DEVICETYPE_MASK) {
-#ifdef ENABLE_EMUL
- case DEVICETYPE_TRIA:
- case DEVICETYPE_TRIV:
case DEVICETYPE_TRIV2:
+#ifdef ENABLE_EMUL
api = new TrinityEmulAPI (id, type);
- break;
#else
- case DEVICETYPE_TRIA:
- api = new TrinityAsrAPI (id);
- break;
- case DEVICETYPE_TRIV:
- api = new TrinityVisionAPI (id);
- break;
- case DEVICETYPE_TRIV2:
api = new TrinityVision2API (id);
- break;
#endif
+ break;
default:
break;
}
static uint32_t api_level_; /**< Trinity API level */
};
-/** @brief Driver APIs for TRIV */
-class TrinityVisionAPI : public DriverAPI {
- public:
- static int getNumDevices ();
- TrinityVisionAPI (int dev_id);
- ~TrinityVisionAPI ();
-
- int open ();
- int checkSanity ();
- int getAPILevel (uint32_t *level) const;
- int getTops (uint32_t *tops) const;
-
- device_state_t isReady () const;
- uint32_t numRequests () const;
-
- int alloc (size_t size) const;
- int dealloc (int dmabuf) const;
- int getMemoryStatus (size_t *alloc, size_t *free) const;
-
- void *mmap (int dmabuf, size_t size) const;
- int munmap (void *addr, size_t size) const;
-
- int runInput (input_config_t *input) const;
- int stop () const;
-
- int registerModel (model_config_t *model, uint64_t npu_version) const;
- int deregisterModel (unsigned long long id) const;
-
- private:
- int getDrvVersion () const;
- static const std::string dev_node_base;
- static std::bitset<CHAR_BIT> dev_bitset;
-
- std::fstream dev_ios_;
-};
-
/** @brief Driver APIs for TRIV2 */
class TrinityVision2API : public DriverAPI {
public:
std::fstream dev_ios_;
};
-/** @brief Driver APIs for TRIA */
-class TrinityAsrAPI : public DriverAPI {
- public:
- static int getNumDevices () { return 0; }
-
- TrinityAsrAPI (int dev_id) : DriverAPI (dev_id) {}
-
- /** TODO: implement API functions for TRIA */
-};
-
#ifdef ENABLE_EMUL
/** @brief emulation element */
+++ /dev/null
-#include "NPUdrvAPI.h"
+++ /dev/null
-#include <misc/trinity.h>
-#include <sys/ioctl.h>
-#include <sys/fcntl.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include <bitset>
-#include <iostream>
-
-#include "NPUdrvAPI.h"
-
-constexpr int max_num_devs = ((1<<CHAR_BIT) - 1);
-constexpr int max_buf_size = 1024;
-
-const std::string TrinityVisionAPI::dev_node_base = "triv";
-std::bitset<CHAR_BIT> TrinityVisionAPI::dev_bitset = 0;
-
-/**
- * @brief constructor of the API instance for Trinity Vision driver
- * @param[in] dev_id device id
- */
-TrinityVisionAPI::TrinityVisionAPI (int dev_id) : DriverAPI (dev_id)
-{
- int num_devs;
-
- if (dev_id > max_num_devs) {
- this->dev_id_ = -1;
- return;
- }
-
- /* Rescan the device nodes to check for newly added or removed one */
- TrinityVisionAPI::dev_bitset.reset ();
- num_devs = TrinityVisionAPI::getNumDevices ();
-
- if ((dev_id > num_devs) || !(TrinityVisionAPI::dev_bitset.test (dev_id))) {
- this->dev_id_ = -1;
- return;
- }
-
- this->dev_id_ = dev_id;
-}
-
-/** @brief destructor of emulation API driver */
-TrinityVisionAPI::~TrinityVisionAPI ()
-{
- if (!(dev_fd_ < 0))
- ::close (dev_fd_);
-}
-
-int
-TrinityVisionAPI::open ()
-{
- std::string path;
- int fd;
-
- if (!this->initialized())
- return -EPERM;
-
- if (dev_id_ == -1)
- return -ENODEV;
-
- path = "/dev/" + TrinityVisionAPI::dev_node_base + "-" +
- std::to_string(dev_id_);
- fd = ::open (path.c_str(), O_RDWR);
- if (fd < 0)
- return -ENODEV;
-
- dev_fd_ = fd;
- return 0;
-}
-
-int
-TrinityVisionAPI::checkSanity ()
-{
- unsigned int lib_ver = trinity_gen_ver (TRINITY_DEV_VISION, VER_NE_MAJOR,
- VER_NE_MINOR, VER_NE_EXTRA);
- unsigned int min_ver = this->getDrvVersion();
-
- // Check if this device is for TRIV1
- if ((lib_ver & TRINITY_MASK_DEV) != (min_ver & TRINITY_MASK_DEV))
- return -ENODEV;
-
- // Check if the major version numbers are same
- if ((lib_ver & TRINITY_MASK_MAJOR_VER) != (min_ver & TRINITY_MASK_MAJOR_VER))
- return -ENOTSUP;
-
- if (lib_ver < min_ver)
- return -ENOTSUP;
-
- return 0;
-}
-
-/**
- * @brief get number of available devices. should be enough
- * @return number of available devices.
- */
-int
-TrinityVisionAPI::getNumDevices ()
-{
- static std::string path;
- struct stat sb;
- int cnt = 0;
- int ret;
-
- path.clear();
-
- for (int i = 0; i < max_num_devs; ++i) {
- path = "/dev/" + TrinityVisionAPI::dev_node_base + "-" + std::to_string(i);
- ret = stat (path.c_str(), &sb);
- if (!ret && S_ISCHR (sb.st_mode)) {
- cnt++;
- TrinityVisionAPI::dev_bitset.set(i);
- }
- }
-
- return cnt;
-}
-
-/**
- * @brief check whether the device is ready or busy. always available.
- * @return true if the device is ready. otherwise false.
- */
-device_state_t
-TrinityVisionAPI::isReady () const
-{
- device_state_t state;
- int ret;
-
- if (!this->initialized())
- return device_state_t::STATE_UNKNOWN;
-
- ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_GET_STATE, &state);
- if (ret != 0)
- return device_state_t::STATE_UNKNOWN;
-
- return state;
-}
-
-/**
- * @brief get the number of requests submitted to the device.
- * @return the number of requests if no error, otherwise 0.
- */
-uint32_t
-TrinityVisionAPI::numRequests () const
-{
- if (this->initialized()) {
- struct trinity_ioctl_stat_apps stat;
- int ret;
-
- ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_STAT_APPS, &stat);
- if (ret == 0) {
- uint32_t num_requests = 0;
-
- for (uint32_t i = 0; i < stat.num_apps; i++)
- num_requests += stat.stat[i].num_active_tasks;
-
- return num_requests;
- }
- }
-
- return 0;
-}
-
-/**
- * @brief allocate memory with the given size
- * @param[in] size the memory size
- * @return dmabuf fd (>= 0) if no error. otherwise a negative errno.
- */
-int
-TrinityVisionAPI::alloc (size_t size) const
-{
- int ret;
-
- if (!this->initialized())
- return -EPERM;
-
- ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_HWMEM_ALLOC, &size);
- if (ret < 0)
- return -errno;
-
- return ret;
-}
-
-/**
- * @brief deallocate memory with the corresponding dmabuf fd
- * @param[in] dmabuf the dmabuf fd to be deallocated
- * @return 0 if no error. otherwise a negative errno.
- */
-int
-TrinityVisionAPI::dealloc (int dmabuf) const
-{
- int ret;
-
- if (!this->initialized())
- return -EPERM;
-
- ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_HWMEM_DEALLOC, &dmabuf);
- if (ret < 0)
- return -errno;
-
- return 0;
-}
-
-/**
- * @brief get the current memory status
- * @param[out] alloc_total The size of allocated memory until now
- * @param[out] free_total The size of freed memory until now
- * @return 0 if no error. otherwise a negatice error value
- */
-int
-TrinityVisionAPI::getMemoryStatus (size_t *alloc_total, size_t *free_total) const
-{
- struct trinity_ioctl_stat_app stat;
- int ret;
-
- if (!initialized())
- return -EPERM;
-
- if (alloc_total == nullptr || free_total == nullptr)
- return -EINVAL;
-
- ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_STAT_CURRENT_APP, &stat);
- if (ret < 0)
- return -errno;
-
- *alloc_total = stat.total_alloc_mem;
- *free_total = stat.total_freed_mem;
-
- return 0;
-}
-
-/**
- * @brief do mmap() for the dmabuf fd
- * @param[in] dmabuf dmabuf fd
- * @param[in] size size to be mmapped
- * @return mmaped address
- * @note it's already memory mapped.
- */
-void *
-TrinityVisionAPI::mmap (int dmabuf, size_t size) const
-{
- void *ret;
-
- if (!this->initialized())
- return nullptr;
-
- ret = ::mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, dmabuf, 0);
- if (ret == MAP_FAILED)
- return nullptr;
-
- return ret;
-}
-
-/**
- * @brief do munmap() for the mmaped pointer
- * @param[in] addr mapped address
- * @param[in] size mapped size
- * @return 0 if no error. otherwise a negative errno
- * @note nothing to do
- */
-int
-TrinityVisionAPI::munmap (void *addr, size_t size) const
-{
- int ret;
-
- if (!this->initialized())
- return -EPERM;
-
- if (addr == nullptr || size == 0)
- return -EINVAL;
-
- ret = ::munmap(addr, size);
-
- return ret;
-}
-
-/**
- * @brief register model config to the driver
- * @param[in] model_config model configuration to be registered
- * @param[in] npu_version npu version described in the metadata
- * @return 0 if no error. otherwise a negative errno
- */
-int
-TrinityVisionAPI::registerModel (model_config_t *model_config,
- uint64_t npu_version) const
-{
- int ret;
-
- if (!this->initialized())
- return -EPERM;
-
- ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_REGISTER_MODEL,
- model_config);
-
- if (ret != 0)
- return -errno;
-
- return ret;
-}
-
-int
-TrinityVisionAPI::deregisterModel (unsigned long long id) const
-{
- int ret;
- if (!this->initialized())
- return -EPERM;
-
- ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_DEREGISTER_MODEL, &id);
-
- if (ret != 0)
- return -errno;
-
- return ret;
-}
-
-/**
- * @brief run inference with the input config
- * @param[in] input_config input configuration for the inference
- * @return 0 or positive id if no error. otherwise a negative errno
- */
-int
-TrinityVisionAPI::runInput (input_config_t *input_config) const
-{
- int ret;
-
- if (!this->initialized())
- return -EPERM;
-
- ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_RUN_INPUT,
- input_config);
-
- if (ret != 0)
- return -errno;
-
- return input_config->task_id;
-}
-
-/**
- * @brief stop all submitted requests.
- * @return 0 if no error, otherwise a negative errno.
- * @note the running request might be not immediately stopped.
- * Also, the stopped requests should be notified to users.
- */
-int
-TrinityVisionAPI::stop () const
-{
- int ret;
-
- if (!this->initialized())
- return -EPERM;
-
- ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_STOP_REQUESTS);
- if (ret != 0)
- return -errno;
-
- return 0;
-}
-
-int
-TrinityVisionAPI::getDrvVersion () const
-{
- int ver;
- int err;
-
- if (!this->initialized())
- return -EPERM;
-
- err = ioctl (this->getDeviceFD (), TRINITY_IOCTL_GET_VERSION, &ver);
- if (err != 0)
- return -errno;
-
- return ver;
-}
-
-int
-TrinityVisionAPI::getAPILevel (uint32_t *level) const
-{
- int err;
-
- if (!this->initialized())
- return -EPERM;
-
- err = ioctl (this->getDeviceFD (), TRINITY_IOCTL_GET_API_LEVEL, level);
- if (err != 0)
- return -errno;
-
- return 0;
-}
-
-/**
- * @brief get TOPS from the driver
- * @param[out] tops npu tops
- * @return 0 if no error. otherwise a negative errno
- */
-int
-TrinityVisionAPI::getTops (uint32_t *tops) const
-{
- int ret;
-
- if (!this->initialized())
- return -EPERM;
-
- ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_GET_TOPS, tops);
- if (ret != 0)
- return -errno;
-
- return ret;
-}
ne_core_npu_inc = include_directories('.')
ne_core_npu_src = [
'NPUdrvAPI.cc',
- 'NPUdrvAPI_triv.cc',
'NPUdrvAPI_triv2.cc',
- 'NPUdrvAPI_tria.cc',
]
if get_option('enable_npu_emul')
+++ /dev/null
-/**
- * Proprietary
- * Copyright (C) 2019 Samsung Electronics
- * Copyright (C) 2019 Dongju Chae <dongju.chae@samsung.com>
- */
-/**
- * @file dummy_tria_sync.c
- * @date 9 Aug 2019
- * @brief AppTest to test ASR inference capability with dummy input/output.
- * @author Dongju Chae <dongju.chae@samsung.com>
- * @bug No known bugs except for NYI items
- */
-
-
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include <libnpuhost.h>
-#include <npubinfmt.h>
-#include <ne_test_utils.h>
-
-/** @brief compare output result with the golden data */
-static int
-compare_result (output_buffers *output)
-{
- return 0;
-}
-
-/** @brief inference entry */
-static int
-run_inference (npudev_h dev)
-{
- uint64_t buffer_size = 4096;
- int err = -1;
-
- input_buffers input;
- output_buffers output;
-
- /** allocate I/O buffers */
- input.num_buffers = 1;
- input.bufs[0].size = buffer_size;
- input.bufs[0].type = BUFFER_MAPPED;
- if ((err = allocNPU_inputBuffers (dev, &input)) != 0)
- goto out;
-
- /** run NPU-ASR inference */
- fill_input_data (&input.bufs[0], 0, buffer_size);
-
- if ((err = runNPU_sync (dev, 0 /* ignored */, &input, &output)) != 0)
- goto out;
-
- /** compare the output result */
- err = compare_result (&output);
-
- cleanNPU_inputBuffers (dev, &input);
-
-out:
- return err;
-}
-
-/** @brief apptest main */
-int
-main (int argc, char **argv)
-{
- int num_devices = getnumNPUdeviceByType (NPUCOND_TRIA_CONN_SOCIP);
- int result = -1;
- npudev_h dev;
-
- if (num_devices > 0) {
- if (getNPUdeviceByType (&dev, NPUCOND_TRIA_CONN_SOCIP, 0) == 0) {
- result = run_inference (dev);
- if (result == 0) {
- fprintf(stderr, "[APPTEST] %s: PASSED\n", argv[0]);
- } else {
- fprintf(stderr, "[APPTEST] %s: FAILED (%d)\n", argv[0], result);
- }
- putNPUdevice (dev);
- }
- } else {
-#if !defined(ENABLE_EMUL)
- /** FastModel doesn't support this application yet */
- return 0;
-#endif
- }
-
- return result;
-}
-
+++ /dev/null
-/**
- * Proprietary
- * Copyright (C) 2019 Samsung Electronics
- * Copyright (C) 2019 Dongju Chae <dongju.chae@samsung.com>
- */
-/**
- * @file dummy_triv_async.c
- * @date 9 Aug 2019
- * @brief AppTest to test output callbacks in async execution.
- * @author Dongju Chae <dongju.chae@samsung.com>
- * @bug No known bugs except for NYI items
- */
-
-#include <libnpuhost.h>
-#include <npubinfmt.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <pthread.h>
-
-#include <ne_test_utils.h>
-
-/** @brief lock for private data */
-#define TEST_LOCK() pthread_mutex_lock(&priv.mutex)
-#define TEST_UNLOCK() pthread_mutex_unlock(&priv.mutex)
-#define TEST_WAKEUP() pthread_cond_broadcast(&priv.cond)
-#define TEST_WAIT() pthread_cond_wait(&priv.cond, &priv.mutex)
-
-typedef struct {
- uint32_t num_callbacks;
- pthread_mutex_t mutex;
- pthread_cond_t cond;
-} test_priv;
-
-#if defined(ENABLE_EMUL)
-const static int TEST_NUM_TESTS = 1024;
-#else
-const static int TEST_NUM_TESTS = 3 * 4;
-#endif
-static test_priv priv;
-
-/**
- * @brief output callback function
- * @param[in] output output buffer
- * @param[in] sequence sequence number of each inference
- * @param[in] data output callback data
- */
-static void
-callback (output_buffers *output, uint64_t sequence, void *data)
-{
- uint32_t idx;
-
- TEST_LOCK();
-
- ++priv.num_callbacks;
-
- /** user needs to free output buffers (if exists) */
- for (idx = 0; idx < output->num_buffers; idx++) {
- assert (output->bufs[idx].type == BUFFER_MAPPED);
- free (output->bufs[idx].addr);
- }
-
- TEST_WAKEUP();
- TEST_UNLOCK();
-}
-
-/**
- * @brief inference entry which repeatedly calls runNPU_async
- * @param[in] dev npu device pointer
- * @return 0 if no error, otherwise a negative error value
- */
-static int
-run_inference (npudev_h dev)
-{
- /* Constants */
- const size_t program_size = 4096;
- const size_t weight_size = 4096;
- const size_t buffer_size = 4096;
- const size_t input_offset = 0;
- const size_t input_size = 1024;
- const size_t output_offset = 512;
- const size_t output_size = 2048;
-
- uint64_t sequence;
- uint32_t model_id;
- int i, err = -1, num_tests = TEST_NUM_TESTS;
-
- generic_buffer * model;
- input_buffers input;
-
- /* make dummy model data */
- npubin_meta meta = {
- /* below are compiler stuff */
- .magiccode = NPUBIN_MAGICCODE | 0x1,
- .name = "dummy model",
- .model_id = 1,
- .model_version = 1,
- .buffer_size = buffer_size,
- .size = NPUBIN_META_SIZE + program_size + weight_size,
- .type = SMODEL_OPS_NPU,
- .input_offset = input_offset,
- .input_size = input_size,
- .output_offset = output_offset,
- .output_size = output_size,
- .program_size = program_size,
- .weight_size = weight_size,
- };
-
- pthread_mutex_init (&priv.mutex, NULL);
- pthread_cond_init (&priv.cond, NULL);
-
- /** make model */
- model = make_model (dev, &meta, BUFFER_MAPPED);
- if (!model)
- goto out;
-
- /** allocate I/O buffers */
- input.num_buffers = 1;
- input.bufs[0].size = buffer_size;
- input.bufs[0].type = BUFFER_MAPPED;
- if ((err = allocNPU_inputBuffers (dev, &input)) != 0)
- goto out_free_model;
-
- /** register the model to NPU Engine */
- if ((err = registerNPUmodel(dev, model, &model_id)) != 0)
- goto out_free_all;
-
- priv.num_callbacks = 0;
-
- /** run NPU inference */
- for (i = 0; i < num_tests; i++) {
- fill_input_data (&input.bufs[0], meta.input_offset, meta.input_size);
- err = runNPU_async (dev, model_id, &input, callback, &sequence, NULL, NPUASYNC_WAIT);
- if (err != 0 || sequence != (uint64_t) (i + 1)) {
- goto out_unregister;
- }
- }
-
- /** wait until all callbacks are called */
- TEST_LOCK();
- while (priv.num_callbacks != num_tests)
- TEST_WAIT();
- err = 0;
- TEST_UNLOCK();
-
-out_unregister:
- unregisterNPUmodel_all (dev);
-out_free_all:
- cleanNPU_inputBuffers (dev, &input);
-out_free_model:
- destroy_model (dev, model);
-out:
- pthread_mutex_destroy (&priv.mutex);
- pthread_cond_destroy (&priv.cond);
-
- return err;
-}
-
-/** @brief apptest main */
-int
-main (int argc, char **argv)
-{
- int num_devices = getnumNPUdeviceByType (NPUCOND_TRIV_CONN_SOCIP);
- int result = -1;
- npudev_h dev;
-
- if (num_devices) {
- 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]);
- else
- fprintf(stderr, "[APPTEST] %s: FAILED (%d)\n", argv[0], result);
- putNPUdevice (dev);
- }
- }
-
- return result;
-}
+++ /dev/null
-/**
- * Proprietary
- * Copyright (C) 2019 Samsung Electronics
- * Copyright (C) 2019 Dongju Chae <dongju.chae@samsung.com>
- * Copyright (C) 2019 Wook Song <wook16.song@samsung.com>
- */
-/**
- * @file dummy_triv_sync.c
- * @date 9 Aug 2019
- * @brief AppTest to test inference capability with dummy input/output.
- * @author Dongju Chae <dongju.chae@samsung.com>
- * Wook Song <wook16.song@samsung.com>
- * @bug No known bugs except for NYI items
- */
-
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include <libnpuhost.h>
-#include <npubinfmt.h>
-#include <ne_test_utils.h>
-
-/** @brief compare output result with the golden data */
-static int
-compare_result (output_buffers *output)
-{
- generic_buffer *buffer;
- int idx;
-
- for (idx = 0; idx < output->num_buffers; idx++) {
- buffer = &output->bufs[idx];
- assert (buffer->type == BUFFER_MAPPED);
- if (buffer->addr != NULL) {
- /* @todo check the contents of output */
- free (buffer->addr);
- }
- }
- return 0;
-}
-
-/** @brief inference entry */
-static int
-run_inference (npudev_h dev)
-{
- /* Constants */
- const size_t program_size = 4096;
- const size_t weight_size = 4096;
- const size_t buffer_size = 4096;
- const size_t input_offset = 0;
- const size_t input_size = 1024;
- const size_t output_offset = 512;
- const size_t output_size = 2048;
-
- uint32_t model_id;
- int err = -1;
-
- generic_buffer * model;
- input_buffers input;
- output_buffers output;
-
- /* make dummy model data */
- npubin_meta meta = {
- /* below are compiler stuff */
- .magiccode = NPUBIN_MAGICCODE | 0x1,
- .name = "dummy model",
- .model_id = 1,
- .model_version = 1,
- .buffer_size = buffer_size,
- .size = NPUBIN_META_SIZE + program_size + weight_size,
- .type = SMODEL_OPS_NPU,
- .input_offset = input_offset,
- .input_size = input_size,
- .output_offset = output_offset,
- .output_size = output_size,
- .program_size = program_size,
- .weight_size = weight_size,
- };
-
- /** make model */
- model = make_model (dev, &meta, BUFFER_MAPPED);
- if (!model)
- goto out;
-
- /** allocate I/O buffers */
- input.num_buffers = 1;
- input.bufs[0].size = buffer_size;
- input.bufs[0].type = BUFFER_MAPPED;
- if ((err = allocNPU_inputBuffers (dev, &input)) != 0)
- goto out_free_model;
-
- /** register the model to NPU Engine */
- if ((err = registerNPUmodel(dev, model, &model_id)) != 0)
- goto out_free_all;
-
- /** run NPU inference */
- fill_input_data (&input.bufs[0], meta.input_offset, meta.input_size);
- if ((err = runNPU_sync (dev, model_id, &input, &output)) != 0)
- goto out_unregister;
-
- /** compare the output result */
- err = compare_result (&output);
-
-out_unregister:
- unregisterNPUmodel(dev, model_id);
-out_free_all:
- cleanNPU_inputBuffers (dev, &input);
-out_free_model:
- destroy_model (dev, model);
-out:
- return err;
-}
-
-/** @brief apptest main */
-int
-main (int argc, char **argv)
-{
- int num_devices = getnumNPUdeviceByType (NPUCOND_TRIV_CONN_SOCIP);
- int result = -1;
- npudev_h dev;
-
- if (num_devices > 0) {
- if (getNPUdeviceByType (&dev, NPUCOND_TRIV_CONN_SOCIP, 0) == 0) {
- result = run_inference (dev);
- if (result == 0) {
- fprintf(stderr, "[APPTEST] %s: PASSED\n", argv[0]);
- } else {
- fprintf(stderr, "[APPTEST] %s: FAILED (%d)\n", argv[0], result);
- }
- putNPUdevice (dev);
- }
- }
-
- return result;
-}
##
# Trinity Device Description
-# - TRIA (Trinity ASR): SR-ASP-IP 2019, not supported yet
-# - TRIV (Trinity Vision): SR-NPU 2019
# - TRIV2 (Trinity Vision2): SR/VD-NPU 2020
## Dummy apptests to check libnpuhost APIs (not expecting outputs)
-executable ('apptest_dummy_tria_sync',
- 'dummy_tria_sync.c',
- include_directories : ne_apptest_inc,
- dependencies : ne_test_utils_dep,
- link_with : ne_library_shared,
- install : b_install_dummy_apptests,
- install_rpath : ne_libdir,
- install_dir : join_paths(ne_bindir, 'apptests')
-)
-
-executable ('apptest_dummy_triv_sync',
- 'dummy_triv_sync.c',
- include_directories : ne_apptest_inc,
- dependencies : ne_test_utils_dep,
- link_with : ne_library_shared,
- install : b_install_dummy_apptests,
- install_rpath : ne_libdir,
- install_dir : join_paths(ne_bindir, 'apptests')
-)
-
-executable ('apptest_dummy_triv_async',
- 'dummy_triv_async.c',
- include_directories : ne_apptest_inc,
- dependencies : ne_test_utils_dep,
- link_with : ne_library_shared,
- install : b_install_dummy_apptests,
- install_rpath : ne_libdir,
- install_dir : join_paths(ne_bindir, 'apptests')
-)
-
executable ('apptest_dummy_triv2_sync',
'dummy_triv2_sync.cc',
include_directories : ne_apptest_inc,
## Apptests to run the compiled tvn models
-executable ('apptest_tvn_triv_bulk',
- 'tvn_triv_bulk.c',
- include_directories : ne_apptest_inc,
- dependencies : ne_test_utils_dep,
- link_with : ne_library_shared,
- install : true,
- install_rpath : ne_libdir,
- install_dir : join_paths(ne_bindir, 'apptests')
-)
-
executable ('apptest_tvn_triv2_bulk',
'tvn_triv2_bulk.cc',
include_directories : ne_apptest_inc,
+++ /dev/null
-/**
- * Proprietary
- * Copyright (C) 2019 Samsung Electronics
- * Copyright (C) 2019 Dongju Chae <dongju.chae@samsung.com>
- */
-/**
- * @file tvn_triv_bulk.c
- * @date 24 Oct 2019
- * @brief AppTest to test example visa binaries (npubinfmt v1/v2)
- * @author Dongju Chae <dongju.chae@samsung.com>
- * @bug No known bugs except for NYI items
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <errno.h>
-
-#include <libnpuhost.h>
-#include <npubinfmt.h>
-#include <ne_test_utils.h>
-
-#define MAX_FILE_LEN 256
-#define NPU_MODEL_NAME "model.tvn"
-
-/** @brief compare output buffers */
-static int
-compare_output_buffers (const npubin_meta *meta, const char *base_path,
- const char *target, output_buffers *output)
-{
- char golden_path[MAX_FILE_LEN];
- char *output_data;
- off_t output_size;
- int err = 0;
-
- /** check output buffers */
- switch (NPUBIN_VERSION (meta->magiccode)) {
- case 0: /* regarded as version 1 */
- case 1:
- {
- if (output->num_buffers != 1) {
- fprintf (stderr, "Support only a single output tensor\n");
- return -EINVAL;
- }
-
- output_data = output->bufs[0].addr;
- output_size = output->bufs[0].size;
-
- memset (golden_path, '\x00', MAX_FILE_LEN);
- snprintf (golden_path, MAX_FILE_LEN, "%s/%s/output_fmap.bin",
- base_path, target);
-
- err = compare_data (golden_path, output_data, output_size);
-
- /**
- * Note that the type of output_buffers can be BUFFER_DMABUF
- * only if input_buffers was provided as external DMABUF memory.
- */
- assert (output->bufs[0].type == BUFFER_MAPPED);
- free (output->bufs[0].addr);
- }
- break;
- case 2:
- {
- uint32_t idx;
-
- for (idx = 0; idx < output->num_buffers; idx++) {
- output_data = output->bufs[idx].addr;
- output_size = output->bufs[idx].size;
-
- memset (golden_path, '\x00', MAX_FILE_LEN);
- snprintf (golden_path, MAX_FILE_LEN, "%s/%s/output_fmap_%d.bin",
- base_path, target, idx);
-
- err = compare_data (golden_path, output_data, output_size);
-
- assert (output->bufs[idx].type == BUFFER_MAPPED);
- free (output->bufs[idx].addr);
-
- if (err != 0)
- break;
- }
- }
- break;
- default:
- assert (0);
- }
-
- return err;
-}
-
-/** @brief run inference for each target visa binary (on sync mode) */
-static int
-run_inference_each (npudev_h dev, const char *base_path, const char *target)
-{
- generic_buffer model;
- input_buffers input;
- output_buffers output;
-
- char model_path[MAX_FILE_LEN];
- char input_path[MAX_TENSORS][MAX_FILE_LEN];
- off_t input_size;
-
- npuConstraint constraint;
- npubin_meta *meta;
- uint32_t model_id;
- uint32_t idx;
- int err = 0;
-
- /** 1: setup model (not dmabuf) */
- memset (model_path, '\x00', MAX_FILE_LEN);
- snprintf (model_path, MAX_FILE_LEN, "%s/%s/%s",
- base_path, target, NPU_MODEL_NAME);
-
- meta = getNPUmodel_metadata (model_path, false);
- if (meta == NULL) {
- fprintf (stderr, "Fail to get the metadata of %s\n", model_path);
- return -EINVAL;
- }
-
- model.size = get_file_size (model_path);
- model.filepath = model_path;
- model.type = BUFFER_FILE;
-
- /** 2: setup input buffers */
- switch (NPUBIN_VERSION (meta->magiccode)) {
- case 0: /* regarded as version 1 */
- case 1:
- {
- memset (input_path[0], '\x00', MAX_FILE_LEN);
- snprintf (input_path[0], MAX_FILE_LEN, "%s/%s/input_fmap.bin",
- base_path, target);
-
- input_size = get_file_size (input_path[0]);
- if (input_size <= 0) {
- fprintf (stderr, "At least one input tensor is required\n");
- err = -EINVAL;
- goto out_free_meta;
- }
-
- input.num_buffers = 1;
- input.bufs[0].size = input_size;
- input.bufs[0].type = BUFFER_FILE;
- input.bufs[0].filepath = input_path[0];
- }
- break;
- case 2:
- {
- for (idx = 0; idx < meta->input_num; idx++) {
- memset (input_path[idx], '\x00', MAX_FILE_LEN);
- snprintf (input_path[idx], MAX_FILE_LEN, "%s/%s/input_fmap_%d.bin",
- base_path, target, idx);
-
- input_size = get_file_size (input_path[idx]);
- if (input_size <= 0) {
- fprintf (stderr, "Wrong metadata; need %d input tensors\n", meta->input_num);
- err = -EINVAL;
- goto out_free_meta;
- }
-
- input.bufs[idx].size = input_size;
- input.bufs[idx].type = BUFFER_FILE;
- input.bufs[idx].filepath = input_path[idx];
- }
-
- input.num_buffers = meta->input_num;
- }
- break;
- default:
- fprintf (stderr, "Unknown metadata version\n");
- err = -EINVAL;
- goto out_free_meta;
- }
-
- /** 3: allocate input buffers (it's not mandatory to use this API) */
- if ((err = allocNPU_inputBuffers (dev, &input)) != 0) {
- fprintf (stderr, "Fail to allocate NPU input buffer (errno %d)\n", err);
- goto out_free_meta;
- }
-
- /** 4: register the model to NPU Engine */
- if ((err = registerNPUmodel (dev, &model, &model_id)) != 0) {
- fprintf (stderr, "Fail to registerNPU model (errno %d)\n", err);
- goto out_clean;
- }
-
- /** 4-1: provide additional information to NPU Engine (npubinfmt v2 only) */
- if (NPUBIN_VERSION (meta->magiccode) == 2) {
- tensors_data_info info_in;
- tensors_data_info info_out;
-
- /* No data manipulation & quantization in this test */
-
- info_in.num_info = meta->input_num;
- for (idx = 0; idx < info_in.num_info; idx++) {
- info_in.info[idx].layout = DATA_LAYOUT_SRNPU;
- info_in.info[idx].type = DATA_TYPE_SRNPU;
- }
-
- info_out.num_info = meta->output_num;
- for (idx = 0; idx < info_out.num_info; idx++) {
- info_out.info[idx].layout = DATA_LAYOUT_SRNPU;
- info_out.info[idx].type = DATA_TYPE_SRNPU;
- }
-
- if ((err = setNPU_dataInfo (dev, model_id, &info_in, &info_out)) != 0) {
- fprintf (stderr, "Failed to set the information for NPU data\n");
- goto out_unregister;
- }
- }
-
- /** 4-2: set constraints */
- constraint.timeout_ms = 100;
- constraint.priority = NPU_PRIORITY_MID;
- constraint.notimode = NPU_INTERRUPT;
- if ((err = setNPU_constraint (dev, model_id, constraint)) != 0)
- goto out_unregister;
-
- /** 5: run NPU inference (sync) */
- if ((err = runNPU_sync (dev, model_id, &input, &output)) != 0)
- goto out_unregister;
-
- /** 6: compare output buffers */
- err = compare_output_buffers (meta, base_path, target, &output);
-
-out_unregister:
- unregisterNPUmodel (dev, model_id);
-out_clean:
- cleanNPU_inputBuffers (dev, &input);
-out_free_meta:
- free (meta);
-
- /** ensure that all memory (allocated by libnpuhost APIs) are successfully freed */
- if (err == 0)
- check_memory_leak (dev);
-
- return err;
-}
-
-/** @brief apptest main */
-int
-main (int argc, char **argv)
-{
- dev_type type = NPUCOND_TRIV_CONN_SOCIP;
- npudev_h dev;
-
- if (argc != 2) {
- fprintf (stderr, "[APPTEST] %s: SKIPPED\n", argv[0]);
- return 0;
- }
-
- if (!(getnumNPUdeviceByType (type) > 0 && getNPUdeviceByType (&dev, type, 0) == 0)) {
- fprintf(stderr, "No available NPU device\n");
- return -1;
- }
-
- return run_apptest (dev, argv, &run_inference_each);
-}
const uint32_t exp_output_num_v1 = 1;
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get(), nullptr);
std::unique_ptr<Buffer> buffer (new Buffer (new HWmemDevice));
TEST (ne_core_buffer_test, buffer_create_tensors_n)
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get(), nullptr);
uint32_t size = 4096;
TEST (ne_core_buffer_test, buffer_get_tensor_n)
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get(), nullptr);
std::unique_ptr<Buffer> buffer (new Buffer (new HWmemDevice));
*/
TEST (ne_core_handler_test, device_create_instance)
{
- dev_type type = NPUCOND_TRIV_CONN_SOCIP;
+ dev_type type = NPUCOND_TRIV2_CONN_SOCIP;
int num_devices = HostHandler::getNumDevices (type);
EXPECT_GT (num_devices, 0);
- /** create TRIV device */
+ /** create TRIV2 device */
int id = num_devices - 1;
std::unique_ptr<Device> device (Device::createInstance (type, id));
ASSERT_NE (device.get (), nullptr);
EXPECT_EQ (device->initialized (), true);
/** other types also work */
- device.reset (Device::createInstance (NPUCOND_CONN_UNKNOWN, 0));
- EXPECT_NE (device.get (), nullptr);
- device.reset (Device::createInstance (NPUCOND_CONN_USB, 0));
- EXPECT_NE (device.get (), nullptr);
- device.reset (Device::createInstance (NPUCOND_CONN_SOCIP, 0));
- EXPECT_NE (device.get (), nullptr);
- device.reset (Device::createInstance (NPUCOND_CONN_PCIE, 0));
- EXPECT_NE (device.get (), nullptr);
- device.reset (Device::createInstance (NPUCOND_CONN_FILESYS, 0));
- EXPECT_NE (device.get (), nullptr);
- device.reset (Device::createInstance (NPUCOND_TRIV_CONN_UNKNOWN, 0));
- EXPECT_NE (device.get (), nullptr);
- device.reset (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ device.reset (Device::createInstance (NPUCOND_TRIV2_CONN_UNKNOWN, 0));
EXPECT_NE (device.get (), nullptr);
}
*/
TEST (ne_core_handler_test, device_create_instance_out_of_range_n)
{
- dev_type type = NPUCOND_TRIV_CONN_SOCIP;
+ dev_type type = NPUCOND_TRIV2_CONN_SOCIP;
int num_devices = HostHandler::getNumDevices (type);
EXPECT_GT (num_devices, 0);
}
/**
- * @brief test Device's createInstance() with unsupported types
- * @todo remove the test codes when available
+ * @brief test Device's createInstance() with invalid types
*/
-TEST (ne_core_handler_test, device_create_instance_unsupported_n)
+TEST (ne_core_handler_test, device_create_instance_invalid_n)
{
EXPECT_EQ (Device::createInstance (static_cast<dev_type> (0x1111), 0), nullptr);
EXPECT_EQ (Device::createInstance (static_cast<dev_type> (0xFFFF), 0), nullptr);
}
/**
+ * @brief test Device's createInstance() with deprecated types
+ */
+TEST (ne_core_handler_test, device_create_instance_deprecated_n)
+{
+ EXPECT_EQ (Device::createInstance (NPUCOND_TRIV_CONN_UNKNOWN, 0), nullptr);
+ EXPECT_EQ (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0), nullptr);
+ EXPECT_EQ (Device::createInstance (NPUCOND_TRIA_CONN_UNKNOWN, 0), nullptr);
+ EXPECT_EQ (Device::createInstance (NPUCOND_TRIA_CONN_SOCIP, 0), nullptr);
+}
+
+/**
* @brief test Device's primitives without initialization
* @note Only createInstance() calls init().
*/
TEST (ne_core_handler_test, device_instance_uninitilized_n)
{
- dev_type type = NPUCOND_TRIV_CONN_SOCIP;
+ dev_type type = NPUCOND_TRIV2_CONN_SOCIP;
int num_devices = HostHandler::getNumDevices (type);
EXPECT_GT (num_devices, 0);
/** directly creating a device instance but not initialized */
- std::unique_ptr<Device> triv (new TrinityVision (0));
- EXPECT_EQ (triv->initialized (), false);
+ std::unique_ptr<Device> triv2 (new TrinityVision2 (0));
+ EXPECT_EQ (triv2->initialized (), false);
void * addr = nullptr;
Model *model;
generic_buffer model_buf;
input_buffers input;
- EXPECT_EQ (triv->allocMemory (4096, &addr), -EPERM);
- EXPECT_EQ (triv->deallocMemory (0, 4096, addr), -EPERM);
- EXPECT_EQ (triv->stop (true), -EPERM);
- EXPECT_EQ (triv->setModel (&model_buf, &model), -EPERM);
- EXPECT_EQ (triv->run (NPUINPUT_HOST, model, &input, nullptr, nullptr, nullptr), -EPERM);
- EXPECT_EQ (triv->unsetModel (model), -EPERM);
-
- std::unique_ptr<Device> triv2 (new TrinityVision2 (0));
- EXPECT_EQ (triv2->initialized (), false);
-
EXPECT_EQ (triv2->allocMemory (4096, &addr), -EPERM);
EXPECT_EQ (triv2->deallocMemory (0, 4096, addr), -EPERM);
EXPECT_EQ (triv2->stop (true), -EPERM);
EXPECT_EQ (triv2->setModel (&model_buf, &model), -EPERM);
EXPECT_EQ (triv2->run (NPUINPUT_HOST, model, &input, nullptr, nullptr, nullptr), -EPERM);
EXPECT_EQ (triv2->unsetModel (model), -EPERM);
-
- std::unique_ptr<Device> tria (new TrinityAsr (0));
- EXPECT_EQ (tria->initialized (), false);
-
- EXPECT_EQ (tria->allocMemory (4096, &addr), -EPERM);
- EXPECT_EQ (tria->deallocMemory (0, 4096, addr), -EPERM);
- EXPECT_EQ (tria->stop (true), -EPERM);
- EXPECT_EQ (tria->setModel (&model_buf, &model), -EPERM);
- EXPECT_EQ (tria->run (NPUINPUT_HOST, model, &input, nullptr, nullptr, nullptr), -EPERM);
- EXPECT_EQ (tria->unsetModel (model), -EPERM);
}
/**
*/
TEST (ne_core_handler_test, device_memory)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
void * addr;
*/
TEST (ne_core_handler_test, device_memory_args_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
void * addr;
create_model_buffer (generic_buffer & model_buf)
{
npubin_meta meta = {0};
+ size_t size = 4096;
+
+ meta.magiccode = NPUBIN_MAGICCODE | 0x3; /** npubinfmt v3 */
- meta.magiccode = NPUBIN_MAGICCODE | 0x1; /** npubinfmt v1 */
- meta.buffer_size = 4096;
- meta.size = 4096;
- meta.input_offset = 0;
- meta.input_size = 4096;
- meta.output_offset = 0;
- meta.output_size = 4096;
/* no instructions */
meta.program_size = 0;
meta.weight_size = 0;
+ meta.size = NPUBIN_META_SIZE;
+
+ meta.segment_num = 2;
+ meta.segment_size[0] = size;
+ meta.segment_size[1] = size;
+
+ meta.weight_seg_idx = 0;
+ meta.input_seg_num = 1;
+ meta.input_seg_idx[0] = 0;
+ meta.input_seg_dims[0][0] = 1;
+ meta.input_seg_dims[0][1] = 1;
+ meta.input_seg_dims[0][2] = 64;
+ meta.input_seg_dims[0][3] = 64;
+
+ meta.output_seg_num = 1;
+ meta.output_seg_idx[0] = 1;
+ meta.output_seg_dims[0][0] = 1;
+ meta.output_seg_dims[0][1] = 1;
+ meta.output_seg_dims[0][2] = 64;
+ meta.output_seg_dims[0][3] = 64;
model_buf.type = BUFFER_MAPPED;
- model_buf.size = NPUBIN_META_SIZE;
- model_buf.addr = new char [NPUBIN_META_SIZE];
+ model_buf.size = meta.size;
+ model_buf.addr = new char [meta.size];
memcpy (model_buf.addr, &meta, NPUBIN_META_SIZE);
}
}
/**
- * @brief test TRIV's setModel ()
+ * @brief test TRIV2's setModel ()
*/
-TEST (ne_core_handler_test, triv_set_model)
+TEST (ne_core_handler_test, triv2_set_model)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
generic_buffer model_buf;
}
/**
- * @brief test TRIV's setModel () with error handling
+ * @brief test TRIV2's setModel () with error handling
*/
-TEST (ne_core_handler_test, triv_set_model_invalid_args_n)
+TEST (ne_core_handler_test, triv2_set_model_invalid_args_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
generic_buffer model_buf;
destroy_model_buffer (model_buf);
}
-/**
- * @brief test TRIV's unsetModel () with error handling
- */
-TEST (ne_core_handler_test, triv_unset_model_n)
-{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
- ASSERT_NE (device.get (), nullptr);
- EXPECT_NE (device->unsetModel (nullptr), 0);
-}
/**
- * @brief test TRIV's setModel () with error handling
+ * @brief test TRIV2's setModel () with error handling
*/
-TEST (ne_core_handler_test, triv_set_model_invalid_data_n)
+TEST (ne_core_handler_test, triv2_set_model_invalid_data_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
generic_buffer model_buf;
destroy_model_buffer (model_buf);
}
-static void
-create_model_buffer_v2 (generic_buffer & model_buf)
+/**
+ * @brief test TRIV2's unsetModel () with error handling
+ */
+TEST (ne_core_handler_test, triv2_unset_model_n)
{
- uint32_t num_tensors = 4;
-
- npubin_meta meta = {0};
-
- meta.magiccode = NPUBIN_MAGICCODE | 0x2; /** npubinfmt v2 */
- meta.buffer_size = (uint64_t) 4096 * (uint64_t) num_tensors;
- meta.size = 4096;
- meta.input_num = num_tensors;
- meta.output_num = num_tensors;
- for (uint32_t i = 0; i < num_tensors; i++) {
- meta.input_elem_size[i] = 1;
- meta.output_elem_size[i] = 1;
-
- meta.input_offsets[i] = 0;
- meta.output_offsets[i] = 0;
- for (uint32_t j = 0; j < MAX_RANK - 1; j++) {
- meta.input_dims[i][j] = 2;
- meta.output_dims[i][j] = 2;
- }
- meta.input_dims[i][MAX_RANK - 1] = DATA_GRANULARITY;
- meta.output_dims[i][MAX_RANK - 1] = DATA_GRANULARITY;
- }
- /* no instructions */
- meta.program_size = 0;
- meta.weight_size = 0;
-
- model_buf.type = BUFFER_MAPPED;
- model_buf.size = NPUBIN_META_SIZE;
- model_buf.addr = new char [NPUBIN_META_SIZE];
-
- memcpy (model_buf.addr, &meta, NPUBIN_META_SIZE);
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ ASSERT_NE (device.get (), nullptr);
+ EXPECT_NE (device->unsetModel (nullptr), 0);
}
static void
create_input_buffers (input_buffers & input_buf)
{
- uint32_t num_buffers = 4;
size_t size = 4096;
- input_buf.num_buffers = num_buffers;
- for (uint32_t i = 0; i < num_buffers; i++) {
- input_buf.bufs[i].type = BUFFER_MAPPED;
- input_buf.bufs[i].size = size;
- input_buf.bufs[i].addr = new char [size];
- }
+ input_buf.num_buffers = 1;
+ input_buf.bufs[0].type = BUFFER_MAPPED;
+ input_buf.bufs[0].size = size;
+ input_buf.bufs[0].addr = new char [size];
}
static void
destroy_input_buffers (input_buffers & input_buf)
{
- for (uint32_t i = 0; i < input_buf.num_buffers; i++) {
- if (input_buf.bufs[i].type == BUFFER_MAPPED)
- delete [] (static_cast<char *> (input_buf.bufs[i].addr));
- }
+ delete [] (static_cast<char *> (input_buf.bufs[0].addr));
}
typedef struct {
/**
* @brief test Device's run ()
*/
-TEST (ne_core_handler_test, triv_run)
+TEST (ne_core_handler_test, triv2_run)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
/** prepare model */
generic_buffer model_buf;
- create_model_buffer_v2 (model_buf);
+ create_model_buffer (model_buf);
Model *model = nullptr;
ASSERT_EQ (device->setModel (&model_buf, &model), 0);
npu_input_opmode opmode = NPUINPUT_HOST;
- /** without callback */
EXPECT_EQ (device->run (opmode, model, &input_buf), 0);
EXPECT_EQ (device->run (opmode, model, &input_buf), 0);
EXPECT_EQ (device->run (opmode, model, &input_buf), 0);
}
/**
- * @brief test TRIV's run () with error handling
+ * @brief test TRIV2's run () with error handling
*/
-TEST (ne_core_handler_test, triv_run_invalid_args_n)
+TEST (ne_core_handler_test, triv2_run_invalid_args_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
- /** TRIV requires valid model and buffer arguments */
+ /** TRIV2 requires valid model and buffer arguments */
/** prepare model */
generic_buffer model_buf;
- create_model_buffer_v2 (model_buf);
+ create_model_buffer (model_buf);
Model *model = nullptr;
ASSERT_EQ (device->setModel (&model_buf, &model), 0);
}
/**
- * @brief test TRIV's run () with error handling
+ * @brief test TRIV2's run () with error handling
*/
-TEST (ne_core_handler_test, triv_run_invalid_opmode_n)
+TEST (ne_core_handler_test, triv2_run_invalid_opmode_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
/** prepare model */
generic_buffer model_buf;
- create_model_buffer_v2 (model_buf);
+ create_model_buffer (model_buf);
Model *model = nullptr;
ASSERT_EQ (device->setModel (&model_buf, &model), 0);
input_buffers input_buf;
create_input_buffers (input_buf);
- /** TRIV only allows NPUINPUT_HOST */
+ /** TRIV2 only allows NPUINPUT_HOST */
EXPECT_NE (device->run (NPUINPUT_STOP, model, &input_buf), 0);
EXPECT_NE (device->run (NPUINPUT_INTERNAL_CAM, model, &input_buf), 0);
EXPECT_NE (device->run (NPUINPUT_I2S_MIC, model, &input_buf), 0);
destroy_input_buffers (input_buf);
destroy_model_buffer (model_buf);
}
-/**
- * @brief test TRIV's prepareInputBuffers () with dma input buffer
- */
-TEST (ne_core_handler_test, triv_prepare_dma_input_buffers)
-{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
- ASSERT_NE (device.get (), nullptr);
-
- /** prepare model */
- generic_buffer model_buf;
- create_model_buffer_v2 (model_buf);
-
- Model *model = nullptr;
- ASSERT_EQ (device->setModel (&model_buf, &model), 0);
-
- /** prepare input buffers */
- input_buffers input_buf;
- create_input_buffers (input_buf);
- input_buf.bufs[0].type = BUFFER_DMABUF;
- input_buf.bufs[0].dmabuf = 1;
- input_buf.bufs[0].size = 4096;
-
- TrinityVision * triv = dynamic_cast<TrinityVision *> (device.get ());
- ASSERT_NE (triv, nullptr);
-
- EXPECT_NE (triv->prepareInputBuffers (model->getMetadata (), & input_buf), nullptr);
-
- destroy_input_buffers (input_buf);
- destroy_model_buffer (model_buf);
-}
-/**
- * @brief test TRIV's prepareInputBuffers () with error handling
- */
-TEST (ne_core_handler_test, triv_prepare_input_buffers_01_n)
-{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
- ASSERT_NE (device.get (), nullptr);
-
- /** prepare model */
- generic_buffer model_buf;
- create_model_buffer_v2 (model_buf);
-
- Model *model = nullptr;
- ASSERT_EQ (device->setModel (&model_buf, &model), 0);
-
- /** prepare input buffers */
- input_buffers input_buf;
- create_input_buffers (input_buf);
-
- TrinityVision * triv = dynamic_cast<TrinityVision *> (device.get ());
- ASSERT_NE (triv, nullptr);
-
- EXPECT_EQ (triv->prepareInputBuffers (nullptr, nullptr), nullptr);
- EXPECT_EQ (triv->prepareInputBuffers (model->getMetadata (), nullptr), nullptr);
- EXPECT_EQ (triv->prepareInputBuffers (nullptr, &input_buf), nullptr);
- /** unmatched metadata */
- input_buf.num_buffers = 2;
- EXPECT_EQ (triv->prepareInputBuffers (model->getMetadata (), &input_buf), nullptr);
-
- destroy_input_buffers (input_buf);
- destroy_model_buffer (model_buf);
-}
-
-/**
- * @brief test TRIV's prepareInputBuffers () with empty input buffers
- */
-TEST (ne_core_handler_test, triv_prepare_input_buffers_02_n)
-{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
- ASSERT_NE (device.get (), nullptr);
-
- /** prepare model */
- generic_buffer model_buf;
- create_model_buffer_v2 (model_buf);
-
- Model *model = nullptr;
- ASSERT_EQ (device->setModel (&model_buf, &model), 0);
-
- /** prepare input buffers */
- input_buffers input_buf;
-
- TrinityVision * triv = dynamic_cast<TrinityVision *> (device.get ());
- ASSERT_NE (triv, nullptr);
- EXPECT_EQ (triv->prepareInputBuffers (model->getMetadata (), & input_buf), nullptr);
-
- destroy_model_buffer (model_buf);
-}
/**
* @brief test Device's stop ()
*/
-TEST (ne_core_handler_test, triv_stop)
+TEST (ne_core_handler_test, triv2_stop)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
/** prepare model */
generic_buffer model_buf;
- create_model_buffer_v2 (model_buf);
+ create_model_buffer (model_buf);
Model *model = nullptr;
ASSERT_EQ (device->setModel (&model_buf, &model), 0);
}
/**
- * @brief testing TRIV's data manipulation
- */
-TEST (ne_core_handler_test, triv_data_manipulation)
-{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
- ASSERT_NE (device.get (), nullptr);
-
- srand (time (NULL));
-
- /* metadata version 2 */
- generic_buffer model_buf;
- create_model_buffer_v2 (model_buf);
-
- /* setup for input tensors */
- input_buffers input_buf;
- create_input_buffers (input_buf);
-
- uint32_t num_tensors = 4;
- uint32_t size_tensor = 4096;
-
- tensors_data_info info;
- info.num_info = num_tensors;
- for (uint32_t i = 0; i < num_tensors; i++) {
- info.info[i].layout = DATA_LAYOUT_NHWC; /* need manipulation */
- info.info[i].type = DATA_TYPE_SRNPU; /* no quantization */
- }
-
- for (uint32_t i = 0; i < num_tensors; i++) {
- /* fill any data */
- for (uint32_t j = 0; j < size_tensor; j++) {
- ((uint8_t *) input_buf.bufs[i].addr)[j] = (i * j) % UINT8_MAX;
- }
- }
-
- npubin_meta *meta = static_cast<npubin_meta *> (model_buf.addr);
-
- /* case 1: no data manipulation (depth == 64) */
- meta->input_num = num_tensors;
- meta->buffer_size = size_tensor;
- for (uint32_t i = 0; i < num_tensors; i++) {
- meta->input_offsets[i] = 0;
- meta->input_elem_size[i] = 1;
- meta->input_dims[i][0] = 1;
- meta->input_dims[i][1] = 8;
- meta->input_dims[i][2] = 8;
- meta->input_dims[i][3] = 64;
- }
-
- Model *model = nullptr;
- ASSERT_EQ (device->setModel (&model_buf, &model), 0);
- EXPECT_EQ (model->setDataInfo (&info, &info), 0);
-
- { /* compare output manipulated */
- std::unique_ptr<uint8_t []> output_data (new uint8_t [meta->buffer_size]);
-
- for (uint32_t i = 0; i < num_tensors; i++) {
- EXPECT_EQ (TrinityVision::manipulateData (model, i, true,
- output_data.get (), input_buf.bufs[i].addr, size_tensor), size_tensor);
- EXPECT_EQ (memcmp (input_buf.bufs[i].addr, output_data.get (), size_tensor), 0);
- }
- }
-
- /* case 2: data manipulation (depth == 16) */
- meta->input_num = num_tensors;
- meta->buffer_size = (uint64_t) size_tensor * (uint64_t) 4;
- for (uint32_t i = 0; i < num_tensors; i++) {
- meta->input_offsets[i] = 0;
- meta->input_elem_size[i] = 1;
- meta->input_dims[i][0] = 1;
- meta->input_dims[i][1] = 16;
- meta->input_dims[i][2] = 16;
- meta->input_dims[i][3] = 16;
- }
-
- ASSERT_EQ (device->setModel (&model_buf, &model), 0);
- EXPECT_EQ (model->setDataInfo (&info, &info), 0);
-
- { /* compare output manipulated */
- std::unique_ptr<uint8_t []> output_data (new uint8_t [meta->buffer_size]);
-
- for (uint32_t i = 0; i < num_tensors; i++) {
- EXPECT_EQ (TrinityVision::manipulateData (model, i, true,
- output_data.get (), input_buf.bufs[i].addr, size_tensor), size_tensor);
- /* non-WPA_L aligned depth needs some zero padding */
- for (uint32_t j = 0; j < size_tensor; j += 16) {
- EXPECT_EQ (memcmp (static_cast<char*> (input_buf.bufs[i].addr) + j,
- output_data.get () + 64 * (j / 16), 16), 0);
- }
- }
- }
-
- /* case 3: data manipulation (depth == 32) */
- meta->input_num = num_tensors;
- meta->buffer_size = (uint64_t) size_tensor * (uint64_t) 2;
- for (uint32_t i = 0; i < num_tensors; i++) {
- meta->input_offsets[i] = 0;
- meta->input_elem_size[i] = 1;
- meta->input_dims[i][0] = 1;
- meta->input_dims[i][1] = 16;
- meta->input_dims[i][2] = 8;
- meta->input_dims[i][3] = 32;
- }
-
- ASSERT_EQ (device->setModel (&model_buf, &model), 0);
- EXPECT_EQ (model->setDataInfo (&info, &info), 0);
-
- { /* compare output manipulated */
- std::unique_ptr<uint8_t []> output_data (new uint8_t [meta->buffer_size]);
-
- for (uint32_t i = 0; i < num_tensors; i++) {
- EXPECT_EQ (TrinityVision::manipulateData (model, i, true,
- output_data.get (), input_buf.bufs[i].addr, size_tensor), size_tensor);
- /* non-WPA_L aligned depth needs some zero padding */
- for (uint32_t j = 0; j < size_tensor; j += 32) {
- EXPECT_EQ (memcmp (static_cast<char*> (input_buf.bufs[i].addr) + j,
- output_data.get () + 64 * (j / 32), 32), 0);
- }
- }
- }
-
- /* case 4: data manipulation (depth == 128) */
- meta->input_num = num_tensors;
- meta->buffer_size = size_tensor;
- for (uint32_t i = 0; i < num_tensors; i++) {
- meta->input_offsets[i] = 0;
- meta->input_elem_size[i] = 1;
- meta->input_dims[i][0] = 1;
- meta->input_dims[i][1] = 4;
- meta->input_dims[i][2] = 8;
- meta->input_dims[i][3] = 128;
- }
-
- ASSERT_EQ (device->setModel (&model_buf, &model), 0);
- EXPECT_EQ (model->setDataInfo (&info, &info), 0);
-
- { /* compare output manipulated */
- std::unique_ptr<uint8_t []> output_data (new uint8_t [meta->buffer_size]);
-
- for (uint32_t i = 0; i < num_tensors; i++) {
- EXPECT_EQ (TrinityVision::manipulateData (model, i, true,
- output_data.get (), input_buf.bufs[i].addr, size_tensor), size_tensor);
- /* 128 is WPA_L-aligned, but data is splitted */
- for (uint32_t j = 0; j < size_tensor; j += 128) {
- EXPECT_EQ (memcmp (static_cast<char*> (input_buf.bufs[i].addr) + j,
- output_data.get () + 64 * (j / 128), 64), 0);
- EXPECT_EQ (memcmp (static_cast<char*> (input_buf.bufs[i].addr) + j + 64,
- output_data.get () + 64 * (j / 128) + size_tensor / 2, 64), 0);
- }
- }
- }
-
- destroy_input_buffers (input_buf);
- destroy_model_buffer (model_buf);
-}
-
-/**
- * @brief test TRIV's quantization during data manipulation
- */
-TEST (ne_core_handler_test, triv_quantization)
-{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
- ASSERT_NE (device.get (), nullptr);
-
- srand (time (NULL));
-
- /* metadata version 2 */
- generic_buffer model_buf;
- create_model_buffer_v2 (model_buf);
-
- /* setup for input tensors */
- input_buffers input_buf;
- create_input_buffers (input_buf);
-
- uint32_t num_tensors = 4;
- uint32_t size_tensor = 4096;
-
- tensors_data_info info;
- info.num_info = num_tensors;
- for (uint32_t i = 0; i < num_tensors; i++) {
- info.info[i].layout = DATA_LAYOUT_NHWC; /* need manipulation */
- info.info[i].type = DATA_TYPE_INT32; /* need quantization */
- }
-
- for (uint32_t i = 0; i < num_tensors; i++) {
- /* fill any data */
- for (uint32_t j = 0; j < size_tensor; j++) {
- ((uint8_t *) input_buf.bufs[i].addr)[j] = (i * j) % UINT8_MAX;
- }
- }
-
- npubin_meta *meta = static_cast<npubin_meta *> (model_buf.addr);
-
- /* case 1: no data manipulation (depth == 64) */
- meta->input_num = num_tensors;
- meta->buffer_size = size_tensor / 4; /** 32bit -> 8bit */
- for (uint32_t i = 0; i < num_tensors; i++) {
- meta->input_offsets[i] = 0;
- meta->input_elem_size[i] = 4; /* int32_t */
- meta->input_dims[i][0] = 1;
- meta->input_dims[i][1] = 4;
- meta->input_dims[i][2] = 4;
- meta->input_dims[i][3] = 64;
-
- meta->input_quant_s[i] = 1000000.0;
- meta->input_quant_z[i] = 127;
- }
-
- Model *model = nullptr;
- ASSERT_EQ (device->setModel (&model_buf, &model), 0);
- EXPECT_EQ (model->setDataInfo (&info, &info), 0);
-
- {
- std::unique_ptr<uint8_t []> output_data (new uint8_t [meta->buffer_size]);
-
- for (uint32_t i = 0; i < num_tensors; i++) {
- EXPECT_EQ (TrinityVision::manipulateData (model, i, true,
- output_data.get (), input_buf.bufs[i].addr, size_tensor), size_tensor);
-
- double zero_point = (double) meta->input_quant_z[i];
- double scale = (double) meta->input_quant_s[i];
- void *each_data_ptr = (char *) output_data.get ();
-
- for (uint32_t j = 0; j < size_tensor / sizeof(float); j++) {
- double val = (double)((int32_t *) input_buf.bufs[i].addr)[j];
-
- val = val / scale;
- val = val + zero_point;
-
- if (val > 255.0)
- val = 255.0;
- else if (val < 0.0)
- val = 0.0;
-
- EXPECT_EQ ((uint8_t) val, ((uint8_t *) each_data_ptr)[j]);
- }
- }
- }
-
- /* case 2: data manipulation (depth == 32) */
- meta->input_num = num_tensors;
- meta->buffer_size = size_tensor / 2; /** 32bit -> 8bit but need zero padding */
- for (uint32_t i = 0; i < num_tensors; i++) {
- meta->input_offsets[i] = 0;
- meta->input_elem_size[i] = 4; /* int32_t */
- meta->input_dims[i][0] = 1;
- meta->input_dims[i][1] = 8;
- meta->input_dims[i][2] = 4;
- meta->input_dims[i][3] = 32;
-
- meta->input_quant_s[i] = 1000000.0;
- meta->input_quant_z[i] = 127;
- }
-
- ASSERT_EQ (device->setModel (&model_buf, &model), 0);
- EXPECT_EQ (model->setDataInfo (&info, &info), 0);
-
- {
- std::unique_ptr<uint8_t []> output_data (new uint8_t [meta->buffer_size]);
-
- for (uint32_t i = 0; i < num_tensors; i++) {
- EXPECT_EQ (TrinityVision::manipulateData (model, i, true,
- output_data.get (), input_buf.bufs[i].addr, size_tensor), size_tensor);
-
- double zero_point = (double) meta->input_quant_z[i];
- double scale = (double) meta->input_quant_s[i];
- void *each_data_ptr = (char *) output_data.get ();
-
- for (uint32_t j = 0; j < size_tensor / sizeof(float); j++) {
- double val = (double)((int32_t *) input_buf.bufs[i].addr)[j];
-
- val = val / scale;
- val = val + zero_point;
-
- if (val > 255.0)
- val = 255.0;
- else if (val < 0.0)
- val = 0.0;
-
- EXPECT_EQ ((uint8_t) val, ((uint8_t *) each_data_ptr)[j % 32 + 64 * (j / 32)]);
- }
- }
- }
-
- destroy_input_buffers (input_buf);
- destroy_model_buffer (model_buf);
-}
-
-/**
- * @brief test TRIV's dequantization during data manipulation
- */
-TEST (ne_core_handler_test, triv_dequantization)
-{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
- ASSERT_NE (device.get (), nullptr);
-
- srand (time (NULL));
-
- /* metadata version 2 */
- generic_buffer model_buf;
- create_model_buffer_v2 (model_buf);
-
- /* setup for input tensors */
- input_buffers input_buf;
- create_input_buffers (input_buf);
-
- uint32_t num_tensors = 4;
- uint32_t size_tensor = 4096;
-
- tensors_data_info info;
- info.num_info = num_tensors;
- for (uint32_t i = 0; i < num_tensors; i++) {
- info.info[i].layout = DATA_LAYOUT_NHWC; /* need manipulation */
- info.info[i].type = DATA_TYPE_FLOAT32; /* need quantization */
- }
-
- for (uint32_t i = 0; i < num_tensors; i++) {
- /* fill any data */
- for (uint32_t j = 0; j < size_tensor / sizeof (float); j++) {
- ((float *) input_buf.bufs[i].addr)[j] = i * j;
- }
- }
-
- npubin_meta *meta = static_cast<npubin_meta *> (model_buf.addr);
-
- /* case 1: no data manipulation (depth == 64) */
- meta->input_num = num_tensors;
- meta->buffer_size = size_tensor / sizeof (float); /** 32bit -> 8bit */
- for (uint32_t i = 0; i < num_tensors; i++) {
- meta->input_offsets[i] = 0;
- meta->input_elem_size[i] = sizeof (float); /* float */
- meta->input_dims[i][0] = 1;
- meta->input_dims[i][1] = 4;
- meta->input_dims[i][2] = 4;
- meta->input_dims[i][3] = 64;
-
- meta->input_quant_s[i] = 10.0;
- meta->input_quant_z[i] = 127;
-
- meta->output_offsets[i] = 0;
- meta->output_elem_size[i] = sizeof (float); /* float */
- meta->output_dims[i][0] = 1;
- meta->output_dims[i][1] = 4;
- meta->output_dims[i][2] = 4;
- meta->output_dims[i][3] = 64;
-
- meta->output_quant_s[i] = 10.0;
- meta->output_quant_z[i] = 127;
- }
-
- Model *model = nullptr;
- ASSERT_EQ (device->setModel (&model_buf, &model), 0);
- EXPECT_EQ (model->setDataInfo (&info, &info), 0);
-
- {
- std::unique_ptr<uint8_t []> output_data (new uint8_t [meta->buffer_size]);
- std::unique_ptr<float []> output_dequant_data (new float [meta->buffer_size]);
-
- double zero_point, scale;
- void *each_data_ptr;
-
- for (uint32_t i = 0; i < num_tensors; i++) {
- EXPECT_EQ (TrinityVision::manipulateData (model, i, true,
- output_data.get (), input_buf.bufs[i].addr, size_tensor), size_tensor);
-
- zero_point = (double) meta->input_quant_z[i];
- scale = (double) meta->input_quant_s[i];
- each_data_ptr = (char *) output_data.get ();
-
- for (uint32_t j = 0; j < size_tensor / sizeof(float); j++) {
- double val = (double)((float *) input_buf.bufs[i].addr)[j];
-
- val = val / scale;
- val = val + zero_point;
-
- if (val > 255.0)
- val = 255.0;
- else if (val < 0.0)
- val = 0.0;
-
- EXPECT_EQ ((uint8_t) val, ((uint8_t *) each_data_ptr)[j]);
- }
-
- EXPECT_EQ (TrinityVision::manipulateData (model, i, false,
- output_dequant_data.get (), output_data.get (), size_tensor / sizeof (float)),
- size_tensor / sizeof (float));
-
- zero_point = (double) meta->output_quant_z[i];
- scale = (double) meta->output_quant_s[i];
- each_data_ptr = (char *) output_dequant_data.get ();
-
- for (uint32_t j = 0; j < size_tensor / sizeof(float); j++) {
- double val = (double)((uint8_t *) output_data.get ())[j];
-
- val = val - zero_point;
- val = val * scale;
-
- ASSERT_DOUBLE_EQ (val, (double)((float *) each_data_ptr)[j]);
- }
- }
- }
-
- /* case 2: data manipulation (depth == 32) */
- meta->input_num = num_tensors;
- meta->buffer_size = size_tensor / sizeof (float) * 2; /** 32bit -> 8bit but need zero padding */
- for (uint32_t i = 0; i < num_tensors; i++) {
- meta->input_offsets[i] = 0;
- meta->input_elem_size[i] = sizeof (float); /* float */
- meta->input_dims[i][0] = 1;
- meta->input_dims[i][1] = 8;
- meta->input_dims[i][2] = 4;
- meta->input_dims[i][3] = 32;
-
- meta->input_quant_s[i] = 10.0;
- meta->input_quant_z[i] = 127;
-
- meta->output_offsets[i] = 0;
- meta->output_elem_size[i] = sizeof (float); /* float */
- meta->output_dims[i][0] = 1;
- meta->output_dims[i][1] = 8;
- meta->output_dims[i][2] = 4;
- meta->output_dims[i][3] = 32;
-
- meta->output_quant_s[i] = 10.0;
- meta->output_quant_z[i] = 127;
- }
-
- ASSERT_EQ (device->setModel (&model_buf, &model), 0);
- EXPECT_EQ (model->setDataInfo (&info, &info), 0);
-
- {
- std::unique_ptr<uint8_t []> output_data (new uint8_t [meta->buffer_size]);
- std::unique_ptr<float []> output_dequant_data (new float [meta->buffer_size]);
-
- double zero_point, scale;
- void *each_data_ptr;
-
- for (uint32_t i = 0; i < num_tensors; i++) {
- EXPECT_EQ (TrinityVision::manipulateData (model, i, true,
- output_data.get (), input_buf.bufs[i].addr, size_tensor), size_tensor);
-
- zero_point = (double) meta->input_quant_z[i];
- scale = (double) meta->input_quant_s[i];
- each_data_ptr = (char *) output_data.get ();
-
- for (uint32_t j = 0; j < size_tensor / sizeof(float); j++) {
- double val = (double)((float *) input_buf.bufs[i].addr)[j];
-
- val = val / scale;
- val = val + zero_point;
-
- if (val > 255.0)
- val = 255.0;
- else if (val < 0.0)
- val = 0.0;
-
- EXPECT_EQ ((uint8_t) val, ((uint8_t *) each_data_ptr)[j % 32 + 64 * (j / 32)]);
- }
-
- EXPECT_EQ (TrinityVision::manipulateData (model, i, false,
- output_dequant_data.get (), output_data.get (), size_tensor / sizeof (float) * 2),
- size_tensor / sizeof (float) * 2);
-
- zero_point = (double) meta->output_quant_z[i];
- scale = (double) meta->output_quant_s[i];
- each_data_ptr = (char *) output_dequant_data.get ();
-
- for (uint32_t j = 0; j < size_tensor / sizeof(float); j++) {
- double val = (double)((uint8_t *) output_data.get ())[j % 32 + 64 * (j / 32)];
-
- val = val - zero_point;
- val = val * scale;
-
- EXPECT_DOUBLE_EQ (val, (double)((float *) each_data_ptr)[j]);
- }
- }
- }
-
- destroy_input_buffers (input_buf);
- destroy_model_buffer (model_buf);
-}
-
-/** TODO: add testcases for other device types (e.g., TRIV2, TRIA) when available */
-
-/**
* @brief test HostHandler's registerModel ()
*/
TEST (ne_core_handler_test, handler_register_model)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
*/
TEST (ne_core_handler_test, handler_register_model_invalid_args_01_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
*/
TEST (ne_core_handler_test, handler_register_model_invalid_args_02_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
*/
TEST (ne_core_handler_test, handler_unregister_model_invalid_id_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
*/
TEST (ne_core_handler_test, handler_get_model_invalid_id_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
*/
TEST (ne_core_handler_test, handler_set_data_info)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
*/
TEST (ne_core_handler_test, handler_set_data_info_invalid_args_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
*/
TEST (ne_core_handler_test, handler_set_constraint)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
*/
TEST (ne_core_handler_test, handler_set_constraint_invalid_args_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
*/
TEST (ne_core_handler_test, handler_generic_buffer)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
*/
TEST (ne_core_handler_test, handler_generic_buffer_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
*/
TEST (ne_core_handler_test, handler_generic_buffers_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
/**
* @brief test HostHandler's runSync ()
*/
-TEST (ne_core_handler_test, handler_triv_run_sync)
+TEST (ne_core_handler_test, handler_triv2_run_sync)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
/**
* @brief test HostHandler's runSync () with error handling
*/
-TEST (ne_core_handler_test, handler_triv_run_sync_n)
+TEST (ne_core_handler_test, handler_triv2_run_sync_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
output_buffers output;
- /** TRIV always requires model and input buffers */
+ /** TRIV2 always requires model and input buffers */
EXPECT_NE (handler->runSync (modelid, nullptr), 0);
EXPECT_NE (handler->runSync (modelid + 1, &input), 0);
EXPECT_NE (handler->runSync (modelid + 1, &input, &output), 0);
/**
* @brief test HostHandler's runAsync ()
*/
-TEST (ne_core_handler_test, handler_triv_run_async)
+TEST (ne_core_handler_test, handler_triv2_run_async)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
/**
* @brief test HostHandler's runAsync () with error handling
*/
-TEST (ne_core_handler_test, handler_triv_run_async_n)
+TEST (ne_core_handler_test, handler_triv2_run_async_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
EXPECT_EQ (handler->allocGenericBuffer (&input), 0);
- /** TRIV always requires model and input buffers */
+ /** TRIV2 always requires model and input buffers */
EXPECT_NE (handler->runAsync (modelid, nullptr), 0);
EXPECT_NE (handler->runAsync (modelid + 1, &input), 0);
/**
* @brief test HostHandler's getMemoryStatus ()
*/
-TEST (ne_core_handler_test, handler_triv_get_memory_status)
+TEST (ne_core_handler_test, handler_triv2_get_memory_status)
{
// disabled until this feature is implemented
#if defined (ENABLE_EMUL)
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
/**
* @brief test HostHandler's getMemoryStatus () with error handling
*/
-TEST (ne_core_handler_test, handler_triv_get_memory_status_n)
+TEST (ne_core_handler_test, handler_triv2_get_memory_status_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
/**
* @brief test HostHandler's stopInternal () with invalid id
*/
-TEST (ne_core_handler_test, handler_triv_stop_internal_n)
+TEST (ne_core_handler_test, handler_triv2_stop_internal_n)
{
- std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler * handler = device->getHostHandler ();
/** use TRIV driver api for this test */
#define INIT_TEST_DRIVER_API()\
- ASSERT_GT (DriverAPI::getNumDevices (NPUCOND_TRIV_CONN_SOCIP), 0); \
+ ASSERT_GT (DriverAPI::getNumDevices (NPUCOND_TRIV2_CONN_SOCIP), 0); \
std::unique_ptr<DriverAPI> api;\
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0); \
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0); \
EXPECT_NE (api.get(), nullptr); \
#ifndef DRM_RDWR
TEST (ne_core_inf_test, invoke)
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
/** create dummy model & buffer */
std::unique_ptr<Model> model (new Model (new HWmemDevice));
TEST (ne_core_inf_test, invoke_opmode_n)
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
/** create dummy model & buffer */
std::unique_ptr<Model> model (new Model (new HWmemDevice));
TEST (ne_core_inf_test, invoke_args_n)
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
/** create dummy model & buffer */
std::unique_ptr<Model> model (new Model (new HWmemDevice));
TEST (ne_core_inf_test, stop)
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
/** create dummy model & buffer */
std::unique_ptr<Model> model (new Model (new HWmemDevice));
TEST (ne_core_inf_test, stop_not_started_n)
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
/** create dummy model & buffer */
std::unique_ptr<Model> model (new Model (new HWmemDevice));
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get(), nullptr);
/** create dummy model & buffer */
TEST (ne_core_inputservice_test, host_submit_args_n)
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get(), nullptr);
/** create dummy model */
TEST (ne_core_inputservice_test, host_submit_same_id_n)
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get(), nullptr);
/** create dummy model */
TEST (ne_core_inputservice_test, host_remove)
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get(), nullptr);
/** create dummy model */
TEST (ne_core_inputservice_test, hw_recurring_submit)
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get(), nullptr);
/** create dummy model */
TEST (ne_core_inputservice_test, hw_recurring_n)
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get(), nullptr);
/** create dummy model */
*/
TEST (ne_core_mem_test, mem_default_primitives)
{
- std::unique_ptr<DriverAPI> api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ std::unique_ptr<DriverAPI> api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get (), nullptr);
/**
*/
TEST (ne_core_mem_test, mem_pool_primitives_n)
{
- std::unique_ptr<DriverAPI> api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ std::unique_ptr<DriverAPI> api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get (), nullptr);
/** 'resv_mem_size' > 0: MemPool (not implemented yet) */
int num_devices;
/** supported device types (currently) */
- num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV_CONN_UNKNOWN);
- EXPECT_GT (num_devices, 0);
- num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV_CONN_SOCIP);
- EXPECT_GT (num_devices, 0);
-
- /** supported device types (currently) */
num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV2_CONN_UNKNOWN);
EXPECT_GT (num_devices, 0);
num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV2_CONN_SOCIP);
EXPECT_GT (num_devices, 0);
-
- /** synonym */
- num_devices = DriverAPI::getNumDevices (NPUCOND_CONN_UNKNOWN);
- EXPECT_GT (num_devices, 0);
- num_devices = DriverAPI::getNumDevices (NPUCOND_CONN_SOCIP);
- EXPECT_GT (num_devices, 0);
}
/**
- * @brief check getNumDevices() error handling
+ * @brief check getNumDevices() for invalid types
*/
-TEST (ne_core_npu_test, get_num_devices_n)
+TEST (ne_core_npu_test, get_num_devices_invalid_n)
{
int num_devices;
}
/**
- * @brief check device statuses
+ * @brief check getNumDevices() for deprecated devices
*/
-TEST (ne_core_npu_test, check_dev_status_triv)
+TEST (ne_core_npu_test, get_num_devices_deprecated_n)
{
- int num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV_CONN_SOCIP);
- ASSERT_GT (num_devices, 0);
-
- std::unique_ptr<DriverAPI> api;
-
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
- EXPECT_NE (api.get(), nullptr);
- EXPECT_GE (api->getDeviceFD(), 0);
- EXPECT_EQ (api->getDeviceID(), 0);
- EXPECT_EQ (api->isReady(), device_state_t::STATE_READY);
+ int num_devices;
- /** open same device */
- std::unique_ptr<DriverAPI> api2;
- api2 = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
- EXPECT_NE (api2.get(), nullptr);
- EXPECT_GE (api2->getDeviceFD(), 0);
- EXPECT_EQ (api2->getDeviceID(), 0);
- EXPECT_EQ (api2->isReady(), device_state_t::STATE_READY);
+ num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV_CONN_UNKNOWN);
+ EXPECT_LE (num_devices, 0);
+ num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV_CONN_SOCIP);
+ EXPECT_LE (num_devices, 0);
- EXPECT_EQ (api->getDeviceID(), api2->getDeviceID());
- /** file descriptors should be different */
- EXPECT_NE (api->getDeviceFD(), api2->getDeviceFD());
+ num_devices = DriverAPI::getNumDevices (NPUCOND_TRIA_CONN_UNKNOWN);
+ EXPECT_LE (num_devices, 0);
+ num_devices = DriverAPI::getNumDevices (NPUCOND_TRIA_CONN_SOCIP);
+ EXPECT_LE (num_devices, 0);
}
/**
/**
* @brief check device statuses with error handling
*/
-TEST (ne_core_npu_test, check_dev_status_triv_n)
-{
- int num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV_CONN_SOCIP);
- ASSERT_GT (num_devices, 0);
-
- std::unique_ptr<DriverAPI> api;
-
- /** invalid id */
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, -1);
- EXPECT_EQ (api.get(), nullptr);
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, num_devices);
- EXPECT_EQ (api.get(), nullptr);
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, num_devices + 1);
- EXPECT_EQ (api.get(), nullptr);
-}
-
-/**
- * @brief check device statuses with error handling
- */
TEST (ne_core_npu_test, check_dev_status_triv2_n)
{
int num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV2_CONN_SOCIP);
size_t alloc, free;
/** create driver APIs not using createDriverAPI() */
- std::unique_ptr<DriverAPI> api (new TrinityVisionAPI (0));
-
- EXPECT_NE (api->open (), 0);
-
- 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));
-
- EXPECT_NE (api->open (), 0);
-
- 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 TrinityAsrAPI (0));
+ std::unique_ptr<DriverAPI> api (new TrinityVision2API (0));
EXPECT_NE (api->open (), 0);
EXPECT_EQ (api->runInput (&input), -EPERM);
#ifdef ENABLE_EMUL
- api.reset (new TrinityEmulAPI (0, NPUCOND_TRIV_CONN_SOCIP));
-
- /** it's possible to do open() */
- ASSERT_EQ (api->open (), 0);
- EXPECT_NE (api->open (), 0);
-
- /** but, not initialized */
- 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));
/** it's possible to do open() */
/**
* @brief manage memory blocks using driver api
*/
-TEST (ne_core_npu_test, manage_mem_triv)
-{
- int num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV_CONN_SOCIP);
- ASSERT_GT (num_devices, 0);
-
- std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
- EXPECT_NE (api.get(), nullptr);
-
- size_t size = 4096;
- int dmabuf = api->alloc (size);
- EXPECT_GE (dmabuf, 0);
-
- void *ptr = api->mmap (dmabuf, size);
- EXPECT_NE (ptr, nullptr);
-
- for (size_t i = 0; i < size; i++)
- static_cast<uint8_t*>(ptr)[i] = static_cast<uint8_t>(i % 256);
-
- EXPECT_EQ (api->munmap (ptr, size), 0);
-
- ptr = api->mmap (dmabuf, size);
- EXPECT_NE (ptr, nullptr);
-
- for (size_t i = 0; i < size; i++)
- EXPECT_EQ (static_cast<uint8_t*>(ptr)[i], static_cast<uint8_t>(i % 256));
-
- EXPECT_EQ (api->munmap (ptr, size), 0);
- EXPECT_EQ (api->dealloc (dmabuf), 0);
-}
-
-/**
- * @brief manage memory blocks using driver api
- */
TEST (ne_core_npu_test, manage_mem_triv2)
{
int num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV2_CONN_SOCIP);
/**
* @brief manage memory blocks using driver api (negative cases)
*/
-TEST (ne_core_npu_test, manage_mem_triv_n)
-{
- int num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV_CONN_SOCIP);
- ASSERT_GT (num_devices, 0);
-
- std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
- EXPECT_NE (api.get(), nullptr);
-
- size_t size = 4096;
- int dmabuf = api->alloc (size);
- ASSERT_GE (dmabuf, 0);
-
- /** alloc */
- EXPECT_LT (api->alloc (0), 0);
-
- /** mmap */
- void *ptr;
- ptr = api->mmap (dmabuf, 0);
- EXPECT_EQ (ptr, nullptr);
- ptr = api->mmap (dmabuf, size + 1);
- EXPECT_EQ (ptr, nullptr);
- ptr = api->mmap (dmabuf, size);
- ASSERT_NE (ptr, nullptr);
-
- /** munmap */
- EXPECT_NE (api->munmap (nullptr, size), 0);
- EXPECT_NE (api->munmap (ptr, 0), 0);
- EXPECT_EQ (api->munmap (ptr, size), 0);
-
- /** dealloc */
- EXPECT_NE (api->dealloc (-1), 0);
- EXPECT_NE (api->dealloc (dmabuf + 1), 0);
- EXPECT_EQ (api->dealloc (dmabuf), 0);
-
- /** mmap after dealloc */
- ptr = api->mmap (dmabuf, size);
- EXPECT_EQ (ptr, nullptr);
-}
-
-/**
- * @brief manage memory blocks using driver api (negative cases)
- */
TEST (ne_core_npu_test, manage_mem_triv2_n)
{
int num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV2_CONN_SOCIP);
model_config_t model;
int num_devices;
- num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV_CONN_SOCIP);
- ASSERT_GT (num_devices, 0);
-
- /** TRIV1 Cases */
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
- ASSERT_NE (api.get(), nullptr);
-
- /** invalid arguments */
- EXPECT_NE (api->registerModel (nullptr), 0);
-
- /** invalid model dmabuf */
- model.dbuf_fd = -1;
- EXPECT_NE (api->registerModel (&model), 0);
-
/** TRIV2 Cases */
num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV2_CONN_SOCIP);
ASSERT_GT (num_devices, 0);
input_config_t input;
int num_devices;
- num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV_CONN_SOCIP);
- ASSERT_GT (num_devices, 0);
-
- /** TRIV1 Cases */
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
- ASSERT_NE (api.get(), nullptr);
-
- /** invalid arguments */
- EXPECT_NE (api->runInput (nullptr), 0);
-
- /** invalid buffer dmabuf */
- input.dbuf_fd = -1;
- EXPECT_NE (api->runInput (&input), 0);
-
- /** still invalid model dmabuf */
- input.dbuf_fd = api->alloc (4096);
- ASSERT_GE (input.dbuf_fd, 0);
- input.model_id = -1;
- EXPECT_NE (api->runInput (&input), 0);
-
- /** TRIV2 Cases */
+ /** TRIV2 Cases */
num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV2_CONN_SOCIP);
ASSERT_GT (num_devices, 0);
/**
* @brief test running inference with valid data
*/
-TEST (ne_core_npu_test, run_inference_triv)
-{
- const size_t size = 4096;
- std::unique_ptr<DriverAPI> api;
- model_config_t model;
- input_config_t input;
- int buffer_dmabuf;
- int model_dmabuf;
- int num_devices;
-
- num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV_CONN_SOCIP);
- ASSERT_GT (num_devices, 0);
-
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
- ASSERT_NE (api.get(), nullptr);
-
- /** register model data */
- model_dmabuf = api->alloc (size);
- EXPECT_GE (model_dmabuf, 0);
-
- model.version = 2;
- model.dbuf_fd = model_dmabuf;
- model.program_offset_addr = 0;
- model.program_size = 0;
- model.metadata_dbuf_fd = model_dmabuf; /* dummy */
-
- EXPECT_EQ (api->registerModel (&model), 0);
-
- /** allocate input data */
- buffer_dmabuf = api->alloc (size);
- EXPECT_GE (buffer_dmabuf, 0);
-
- /** run with this model */
- input.dbuf_fd = buffer_dmabuf;
- input.model_id = model.id;
-
- EXPECT_GE (api->runInput (&input), 0);
- EXPECT_EQ (api->deregisterModel (model.id), 0);
- EXPECT_EQ (api->dealloc (model_dmabuf), 0);
- EXPECT_EQ (api->dealloc (buffer_dmabuf), 0);
-}
-
-/**
- * @brief test running inference with valid data
- */
TEST (ne_core_npu_test, run_inference_triv2)
{
const size_t size = 4096;
TEST (ne_core_sched_test, submit_request)
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get(), nullptr);
/** create dummy model & buffer */
TEST (ne_core_sched_test, submit_request_args_n)
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get(), nullptr);
/** create dummy model & buffer */
TEST (ne_core_sched_test, submit_request_opmode_n)
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get(), nullptr);
/** create dummy model & buffer */
TEST (ne_core_sched_test, submit_request_empty_n)
{
std::unique_ptr<DriverAPI> api;
- api = DriverAPI::createDriverAPI (NPUCOND_TRIV_CONN_SOCIP, 0);
+ api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get(), nullptr);
Scheduler * sched = new Scheduler (api.get ());
*/
TEST (ne_libnpuhost_test, get_num_devices)
{
- EXPECT_GT (getnumNPUdeviceByType (NPUCOND_TRIV_CONN_SOCIP), 0);
EXPECT_GT (getnumNPUdeviceByType (NPUCOND_TRIV2_CONN_SOCIP), 0);
-
- /* other aliases also work */
- EXPECT_GT (getnumNPUdeviceByType (NPUCOND_CONN_UNKNOWN), 0);
- EXPECT_GT (getnumNPUdeviceByType (NPUCOND_CONN_USB), 0);
- EXPECT_GT (getnumNPUdeviceByType (NPUCOND_CONN_SOCIP), 0);
- EXPECT_GT (getnumNPUdeviceByType (NPUCOND_CONN_PCIE), 0);
- EXPECT_GT (getnumNPUdeviceByType (NPUCOND_CONN_FILESYS), 0);
-
- EXPECT_GT (getnumNPUdeviceByType (NPUCOND_TRIV_CONN_UNKNOWN), 0);
EXPECT_GT (getnumNPUdeviceByType (NPUCOND_TRIV2_CONN_UNKNOWN), 0);
-
- /* TRIA is not supported in FastModel */
-#if defined(ENABLE_EMUL)
- EXPECT_GT (getnumNPUdeviceByType (NPUCOND_TRIA_CONN_SOCIP), 0);
- EXPECT_GT (getnumNPUdeviceByType (NPUCOND_TRIA_CONN_UNKNOWN), 0);
-
- EXPECT_GT (getnumNPUdeviceByType (NPUCOND_ASR_CONN_SOCIP), 0);
- EXPECT_GT (getnumNPUdeviceByType (NPUCOND_ASR_CONN_UNKNOWN), 0);
-#endif
}
/**
}
static dev_type test_types[] = {
- NPUCOND_TRIV_CONN_SOCIP,
-#if defined(ENABLE_EMUL)
- NPUCOND_TRIA_CONN_SOCIP,
-#endif
NPUCOND_TRIV2_CONN_SOCIP
};
}
/**
- * @brief test APIs to run model with input data (TRIV)
- */
-TEST (ne_libnpuhost_test, run_input_triv_binfmt_v1)
-{
- UtilTRIV tester;
-
- ASSERT_EQ (tester.init (), 0);
-
- std::string model_dir (NE_DATADIR);
- model_dir += "/testdata/npubinfmt_v1/testcase1";
-
- uint32_t model_id = 0;
-
- if (tester.loadModel (model_dir, &model_id) != 0)
- /* skip */
- return;
-
- EXPECT_EQ (tester.run (model_id, true), 0);
- EXPECT_EQ (tester.run (model_id, false), 0);
-
- EXPECT_EQ (tester.runAll (true), 0);
- EXPECT_EQ (tester.runAll (false), 0);
-
- EXPECT_EQ (tester.wait (), 4);
-}
-
-/**
- * @brief test APIs to run model with input data (TRIV) (negative cases)
- */
-TEST (ne_libnpuhost_test, run_input_triv_binfmt_v1_n)
-{
- UtilTRIV tester;
-
- /* without init */
- EXPECT_NE (tester.run (0, true), 0);
- EXPECT_NE (tester.run (0, false), 0);
-
- ASSERT_EQ (tester.init (), 0);
-
- /* run without model */
- EXPECT_NE (tester.run (0, true), 0);
- EXPECT_NE (tester.run (0, false), 0);
-
- /* invalid model id */
- std::string model_dir (NE_DATADIR);
- model_dir += "/testdata/npubinfmt_v1/testcase1";
-
- uint32_t model_id = 0;
-
- if (tester.loadModel (model_dir, &model_id) != 0)
- /* skip */
- return;
-
- EXPECT_NE (tester.run (model_id + 1, true), 0);
-}
-
-/**
- * @brief test APIs to run model with input data (TRIV)
- */
-TEST (ne_libnpuhost_test, run_input_triv_binfmt_v2)
-{
- UtilTRIV tester;
-
- ASSERT_EQ (tester.init (), 0);
-
- std::string model_dir (NE_DATADIR);
- model_dir += "/testdata/npubinfmt_v2/testcase1";
-
- uint32_t model_id = 0;
-
- if (tester.loadModel (model_dir, &model_id) != 0)
- /* skip */
- return;
-
- EXPECT_EQ (tester.run (model_id, true), 0);
- EXPECT_EQ (tester.run (model_id, false), 0);
-
- EXPECT_EQ (tester.runAll (true), 0);
- EXPECT_EQ (tester.runAll (false), 0);
-
- EXPECT_EQ (tester.wait (), 4);
-}
-
-/**
- * @brief test APIs to run model with input data (TRIV) (negative cases)
- */
-TEST (ne_libnpuhost_test, run_input_triv_binfmt_v2_n)
-{
- UtilTRIV tester;
-
- /* without init */
- EXPECT_NE (tester.run (0, true), 0);
- EXPECT_NE (tester.run (0, false), 0);
-
- ASSERT_EQ (tester.init (), 0);
-
- /* run without model */
- EXPECT_NE (tester.run (0, true), 0);
- EXPECT_NE (tester.run (0, false), 0);
-
- /* invalid model id */
- std::string model_dir (NE_DATADIR);
- model_dir += "/testdata/npubinfmt_v2/testcase1";
-
- uint32_t model_id = 0;
-
- if (tester.loadModel (model_dir, &model_id) != 0)
- /* skip */
- return;
-
- EXPECT_NE (tester.run (model_id + 1, true), 0);
-}
-
-#if defined(ENABLE_EMUL)
-/**
- * @brief test APIs to run model with input data (TRIA)
- */
-TEST (ne_libnpuhost_test, run_input_tria)
-{
- UtilTRIA tester;
-
- ASSERT_EQ (tester.init (), 0);
-
- EXPECT_EQ (tester.run (0, true), 0);
- EXPECT_EQ (tester.run (0, false), 0);
-
- EXPECT_EQ (tester.wait (), 2);
-}
-
-/**
- * @brief test APIs to run model with input data (TRIA) (negative cases)
- */
-TEST (ne_libnpuhost_test, run_input_tria_n)
-{
- UtilTRIA tester;
-
- /* without init */
- EXPECT_NE (tester.run (0, true), 0);
- EXPECT_NE (tester.run (0, false), 0);
-}
-
-#endif
-
-/**
* @brief test APIs to run model with input data (TRIV2)
*/
TEST (ne_libnpuhost_test, run_input_triv2_binfmt_v3)
uint32_t
TrinitySMI::get_api_level ()
{
- dev_type types[] = {NPUCOND_TRIV_CONN_SOCIP, NPUCOND_TRIV2_CONN_SOCIP};
+ dev_type types[] = {NPUCOND_TRIV2_CONN_SOCIP};
uint32_t level = 0;
for (auto type : types) {
type = NPUCOND_CONN_UNKNOWN;
if (node_.find ("triv2-") != string::npos)
type = NPUCOND_TRIV2_CONN_SOCIP;
- else if (node_.find ("triv-") != string::npos)
- type = NPUCOND_TRIV_CONN_SOCIP;
- else if (node_.find ("tria-") != string::npos)
- type = NPUCOND_TRIA_CONN_SOCIP;
if (dev_id < 0 || type == NPUCOND_CONN_UNKNOWN) {
ss_ << "| Invalid device node provided: " << left << setw(29) << node_ << "|\n";
TrinitySMI::append_devices ()
{
dev_type types[] = {
- NPUCOND_TRIV_CONN_SOCIP,
NPUCOND_TRIV2_CONN_SOCIP,
- NPUCOND_TRIA_CONN_SOCIP
};
ss_ << "\n";
for (auto type : types) {
string cls, node;
- if (type & DEVICETYPE_TRIV) {
- cls = string ("TRIV");
- node = string ("/dev/triv");
- } else if (type & DEVICETYPE_TRIV2) {
+ if (type & DEVICETYPE_TRIV2) {
cls = string ("TRIV2");
node = string ("/dev/triv2");
- } else if (type & DEVICETYPE_TRIA) {
- cls = string ("TRIA");
- node = string ("/dev/tria");
} else {
break;
}