This patch adds missing unsetModel() to call api->deregisterModel().
Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
int
HostHandler::unregisterModel (uint32_t modelid)
{
+ Model *model = models_.find (modelid);
+ if (model == nullptr)
+ return -ENOENT;
+
+ int status = device_->unsetModel (model);
+ if (status != 0) {
+ logerr (TAG, "Failed to unset model: %d\n", status);
+ return status;
+ }
+
return models_.remove (modelid);
}
}
/**
+ * @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
return status;
}
+/**
+ * @brief implementation of TRIV2's unsetModel ()
+ * @param[in] model the model instance
+ * @return 0 if no error, otherwise a negative errno
+ */
+int
+TrinityVision2::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 TRIV2's run() */
int
TrinityVision2::run (npu_input_opmode opmode, const Model *model,
/** virtual methods to implement each device's behaviors */
virtual int setModel (const generic_buffer *model, Model ** model_ptr) { return -EPERM; }
+ virtual int unsetModel (Model * model) { return -EPERM; }
+
virtual int run (npu_input_opmode opmode, const Model *model,
const input_buffers *input, npuOutputNotify cb = nullptr,
void *cb_data = nullptr, uint64_t *sequence = nullptr) = 0;
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);
SegmentTable * prepareSegmentTable (const Model *model, 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);
int runInput (input_config_t *input) const;
int registerModel (model_config_t *model) const;
+ int deregisterModel (unsigned long long id) const;
private:
static std::atomic<int> global_fd_;
uint64_t getInternalId () const { return internal_id_; }
void setModelConfig (model_config_t *model) {
- model_ = *model;
+ model_.reset (model);
}
- model_config_t & getModelConfig () {
- return model_;
+ model_config_t * getModelConfig () {
+ return model_.get();
}
private:
size_t size_; /**< the allocated size */
uint64_t internal_id_;
- model_config_t model_;
+ std::unique_ptr<model_config_t> model_;
};
/**
assert (addr_);
memset (addr_, '\x00', size);
- memset (&model_, '\x00', sizeof (model_config_t));
+ model_.reset(nullptr);
size_ = size;
dmabuf_ = global_id_.fetch_add (1);
if (elem == nullptr)
return -ENOENT;
- elem->setModelConfig (model_config);
+ model_config_t * config = new model_config_t;
+
model_config->id = elem->getInternalId ();
+ memcpy (config, model_config, sizeof (model_config_t));
+
+ elem->setModelConfig (config);
+
+ return 0;
+}
+
+/**
+ * @brief deregister model config to the driver
+ * @param[in] id the model id to be deregistered
+ * @return 0 if no error. otherwise a negative errno
+ */
+int
+TrinityEmulAPI::deregisterModel (unsigned long long id) const
+{
+ if (!initialized())
+ return -EPERM;
+
+ int dbuf_fd = id & TRINITY_MASK_MODEL_DBUF_FD;
+ EmulElement *elem = elem_map_.find (dbuf_fd);
+ if (elem == nullptr)
+ return -ENOENT;
+
+ elem->setModelConfig (nullptr);
return 0;
}
char * addr_model = static_cast<char *>(elem_model->getAddr ());
char * addr_input = static_cast<char *>(elem_input->getAddr ());
- model_config_t model = elem_model->getModelConfig ();
+ model_config_t * model = elem_model->getModelConfig ();
/**
* call NPU C-emulation codes (AIP/NPU_SystemService_Emulator)
*/
if ((dev_type_ & DEVICETYPE_MASK) == DEVICETYPE_TRIV) {
- run_triv_emul (addr_model + model.program_offset_addr, model.program_size,
+ run_triv_emul (addr_model + model->program_offset_addr, model->program_size,
addr_input);
} else if ((dev_type_ & DEVICETYPE_MASK) == DEVICETYPE_TRIV2) {
if (input_config->num_segments <= 0)
segment_table[i] = static_cast<char *>(elem->getAddr ()) + offset;
}
- run_triv2_emul (addr_model + model.program_offset_addr, model.program_size,
+ run_triv2_emul (addr_model + model->program_offset_addr, model->program_size,
segment_table, num_segs);
delete [] segment_table;
}