This patch adds the routine to check the TOPS device supports.
It compares the device's TOPS and model-described TOPS.
For backward-compatability, if TOPS is zero, it's regarded as "don't care"
Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
config.metadata_extra_addr = NPUBIN_META_SIZE;
config.metadata_extra_size = model->getMetadata()->getMetaExtraSize ();
- status = api_->registerModel (&config);
+ status = api_->registerModel (&config, model->getMetadata()->getNPUVersion());
if (status != 0)
goto delete_exit;
uint32_t getMetaExtraSize () const { return NPUBIN_META_EXTRA_SIZE(meta_->magiccode); }
int getVersion () const { return version_; }
+ uint64_t getNPUVersion () const { return meta_->npu_version; }
protected:
Metadata (npubin_meta *meta);
virtual int stop_target (int id) const { return -EPERM; }
/** @brief register model config to the driver */
- virtual int registerModel (model_config_t *model) const { return -EPERM; }
+ virtual int registerModel (model_config_t *model,
+ uint64_t npu_version = 0) const { return -EPERM; }
virtual int deregisterModel (unsigned long long id) const { return -EPERM; }
#if defined(ENABLE_FPGA_WORKAROUND)
int runInput (input_config_t *input) const;
int stop () const;
- int registerModel (model_config_t *model) const;
+ int registerModel (model_config_t *model, uint64_t npu_version) const;
int deregisterModel (unsigned long long id) const;
private:
int stop () const;
int stop_target (int id) const;
- int registerModel (model_config_t *model) const;
+ int registerModel (model_config_t *model, uint64_t npu_version) const;
int deregisterModel (unsigned long long id) const;
#if defined(ENABLE_FPGA_WORKAROUND)
int stop () const;
int stop_target (int id) const;
- int registerModel (model_config_t *model) const;
+ int registerModel (model_config_t *model, uint64_t npu_version) const;
int deregisterModel (unsigned long long id) const;
int getProfile (int task_id, void **profile_buf,
/**
* @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
-TrinityEmulAPI::registerModel (model_config_t *model_config) const
+TrinityEmulAPI::registerModel (model_config_t *model_config,
+ uint64_t npu_version) const
{
static std::atomic<uint64_t> global_internal_id (0);
/**
* @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) const
+TrinityVisionAPI::registerModel (model_config_t *model_config,
+ uint64_t npu_version) const
{
int ret;
#include <iostream>
#include "NPUdrvAPI.h"
+#include <npubinfmt.h>
constexpr int max_num_devs = ((1<<CHAR_BIT) - 1);
constexpr size_t max_buf_size = (256 * PAGE_SIZE);
/**
* @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
-TrinityVision2API::registerModel (model_config_t *model_config) const
+TrinityVision2API::registerModel (model_config_t *model_config,
+ uint64_t npu_version) const
{
+ uint32_t model_tops;
+ uint32_t device_tops;
int ret;
if (!this->initialized())
return -EPERM;
+ if (NPU_VERSION_MAJOR(npu_version) != 2)
+ return -EINVAL;
+
+ model_tops = NPU_VERSION_TOPS(npu_version);
+ if (model_tops != 0) {
+ ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_GET_TOPS,
+ &device_tops);
+ if (ret != 0)
+ return -errno;
+
+ if (model_tops != device_tops)
+ return -EINVAL;
+ } /** else: don't care */
+
ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_REGISTER_MODEL,
model_config);
#include "ne_unittest_utils.h"
+/** 8-TOPS TRIV2 v2.2.1 */
+#define TEST_NPU_VERSION (0x08010202)
+
/**
* @brief check getNumDevices()
*/
model.program_size = 0;
model.metadata_dbuf_fd = model_dmabuf; /* dummy */
- EXPECT_EQ (api->registerModel (&model), 0);
+ EXPECT_EQ (api->registerModel (&model, TEST_NPU_VERSION), 0);
/** allocate input data */
buffer_dmabuf = api->alloc (size);
model.program_size = 0;
model.metadata_dbuf_fd = model_dmabuf; /* dummy */
- EXPECT_EQ (api->registerModel (&model), 0);
+ EXPECT_EQ (api->registerModel (&model, TEST_NPU_VERSION), 0);
int *buf = nullptr;
int buffer_dmabuf = -1;
model.program_size = 0;
model.metadata_dbuf_fd = ret; /* dummy */
- ret = api->registerModel (&model);
+ ret = api->registerModel (&model, TEST_NPU_VERSION);
if (ret < 0) {
model.dbuf_fd = -1;
}
model.program_offset_addr = 0;
model.program_size = 0;
- EXPECT_EQ (api->registerModel (&model), 0);
+ EXPECT_EQ (api->registerModel (&model, TEST_NPU_VERSION), 0);
/** allocate input data */
buffer_dmabuf = api->alloc (size);