This patch renames 'task' to 'request'.
As VD I/F has used 'task' to describe scheduling task, it makes confusion.
Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
* other requests. FIFO is used among the same priority requests.
*/
typedef enum {
- NPU_PRIORITY_LOW = 0, /**< Low priority: tasks could be delayed or canceled */
- NPU_PRIORITY_MID = 1, /**< Mid priority: tasks could be slightly delayed */
- NPU_PRIORITY_HIGH = 2, /**< High priority: tasks should be issued immediately */
+ NPU_PRIORITY_LOW = 0, /**< Low priority: requests could be delayed or canceled */
+ NPU_PRIORITY_MID = 1, /**< Mid priority: requests could be slightly delayed */
+ NPU_PRIORITY_HIGH = 2, /**< High priority: requests should be issued immediately */
NPU_PRIORITY_PROFILE = NPU_PRIORITY_HIGH /**< Deprecated */
} npu_priority;
} npu_app_status;
/**
- * @brief Description of npu task (per inference) status
+ * @brief Description of npu request (per inference) status
*/
typedef enum {
- NPU_TASK_UNKNOWN = 0,
- NPU_TASK_ERROR = 1,
- NPU_TASK_PENDING = 2,
- NPU_TASK_RUNNING = 3,
- NPU_TASK_FINISHED = 4,
-} npu_task_status;
+ NPU_REQ_UNKNOWN = 0,
+ NPU_REQ_ERROR = 1,
+ NPU_REQ_PENDING = 2,
+ NPU_REQ_RUNNING = 3,
+ NPU_REQ_FINISHED = 4,
+} npu_req_status;
typedef struct {
- int appid;
+ int app_id;
char name[16];
npu_app_status status;
- uint32_t num_total_tasks;
- uint32_t num_active_tasks;
+ uint32_t num_total_reqs;
+ uint32_t num_active_reqs;
uint64_t total_alloc_mem;
uint64_t total_freed_mem;
} npu_stat_apps;
typedef struct {
- int taskid;
- uint64_t modelid;
+ int req_id;
+ uint64_t model_id;
npu_priority priority;
- npu_task_status status;
+ npu_req_status status;
uint32_t sched_time;
uint32_t infer_time;
-} npu_stat_task;
+} npu_stat_req;
typedef struct {
uint32_t num;
- npu_stat_task *stat;
-} npu_stat_tasks;
+ npu_stat_req *stat;
+} npu_stat_reqs;
/**
* NPU Profiling (both for emulated/real-device envionment)
* @brief Send the NN model to NPU.
* @param[in] dev The NPU device handle
* @param[in] modelfile The filepath to the compiled NPU NN model in any buffer_type
- * @param[out] modelid The modelid allocated for this instance of NN model.
+ * @param[out] model_id The modelid allocated for this instance of NN model.
* @return @c 0 if no error. otherwise a negative error value
*
* @detail For ASR devices, which do not accept models, but have models
* embedded in devices, you do not need to call register and
* register calls for ASR are ignored.
*/
-int registerNPUmodel(npudev_h dev, generic_buffer *modelfile, uint32_t *modelid);
+int registerNPUmodel(npudev_h dev, generic_buffer *modelfile, uint32_t *model_id);
/**
* @brief Remove the NN model from NPU
* @return @c 0 if no error. otherwise a negative error value
* @detail This may incur some latency with memory compatcion.
*/
-int unregisterNPUmodel(npudev_h dev, uint32_t modelid);
+int unregisterNPUmodel(npudev_h dev, uint32_t model_id);
/**
* @brief Remove all NN models from NPU
/**
* @brief [OPTIONAL] Set the data layout for input/output tensors
* @param[in] dev The NPU device handle
- * @param[in] modelid The ID of model whose layouts are set
+ * @param[in] model_id The ID of model whose layouts are set
* @param[in] info_in the layout/type info for input tensors
* @param[in] info_out the layout/type info for output tensors
* @return @c 0 if no error. otherwise a negative error value
* @note if this function is not called, default layout/type will be used.
*/
-int setNPU_dataInfo(npudev_h dev, uint32_t modelid,
+int setNPU_dataInfo(npudev_h dev, uint32_t model_id,
tensors_data_info *info_in, tensors_data_info *info_out);
/**
* @brief [OPTIONAL] Set the inference constraint for next NPU inferences
* @param[in] dev The NPU device handle
- * @param[in] modelid The target model id
+ * @param[in] model_id The target model id
* @param[in] constraint inference constraint (e.g., timeout, priority)
* @return @c 0 if no error. otherwise a negative error value
* @note If this function is not called, default values are used.
*/
-int setNPU_constraint(npudev_h dev, uint32_t modelid, npuConstraint constraint);
+int setNPU_constraint(npudev_h dev, uint32_t model_id, npuConstraint constraint);
/**
* @brief Execute inference. Wait (block) until the output is available.
* @param[in] dev The NPU device handle
- * @param[in] modelid The model to be inferred.
+ * @param[in] model_id The model to be inferred.
* @param[in] input The input data to be inferred.
* @param[out] output The output result. The caller MUST allocate appropriately before calling this.
* @return @c positive id if no error. otherwise a negative error value
* @detail This is a syntactic sugar of runNPU_async().
* CAUTION: There is a memcpy for the output buffer.
*/
-int runNPU_sync(npudev_h dev, uint32_t modelid, const input_buffers *input,
+int runNPU_sync(npudev_h dev, uint32_t model_id, const input_buffers *input,
output_buffers *output);
/**
* @brief Let NPU accept input frames from its internal source continuously
* @param[in] dev The NPU device handle
- * @param[in] modelid The model to be inferred.
+ * @param[in] model_id The model to be inferred.
* @param[in] opmode NPU has different opmode with auto-inputs. Choose one.
* @param[in] hw_dev The target device feeding input data
* @return @c positive id if no error. otherwise a negative error value
* @note input and output are handled internally by third-party HW (e.g., DSP)
*/
-int runNPU_internalInput(npudev_h dev, uint32_t modelid, npu_input_opmode opmode,
+int runNPU_internalInput(npudev_h dev, uint32_t model_id, npu_input_opmode opmode,
const char * hw_dev);
/**
/**
* @brief Invoke NPU inference. Unblocking call.
* @param[in] dev The NPU device handle
- * @param[in] modelid The model to be inferred.
+ * @param[in] model_id The model to be inferred.
* @param[in] input The input data to be inferred.
* @param[in] cb The output buffer handler.
* @param[out] sequence The sequence number returned with runNPU_async.
* @param[in] mode Configures how this operation works.
* @return @c positive id if no error. otherwise a negative error value
*/
-int runNPU_async(npudev_h dev, uint32_t modelid, const input_buffers *input,
+int runNPU_async(npudev_h dev, uint32_t model_id, const input_buffers *input,
npuOutputNotify cb, uint64_t *sequence, void *data,
npu_async_mode mode);
/**
* @brief Get the profile information from NPU
* @param[in] dev NPU device handle
- * @param[in] task_id Identifier for each inference (obtained by runNPU_*)
+ * @param[in] req_id Identifier for each inference (obtained by runNPU_*)
* @param[out] profile Profile instance
* @return 0 if no error, otherwise a negative errno.
*/
-int getNPU_profile (npudev_h dev, int task_id, npu_profile *profile);
+int getNPU_profile (npudev_h dev, int req_id, npu_profile *profile);
/**
* @brief Free the profile instance obtained by getNPU_profile().
void putNPU_statApps (npu_stat_apps *stat);
/**
- * @brief get the stats for the latest tasks of the target app
+ * @brief get the stats for the latest requests of the target app
* @param[in] dev The NPU device handle
- * @param[in] appid The identifier of target app (obtained by getNPU_statApps)
- * @param[out] stat The list of task stat
+ * @param[in] app_id The identifier of target app (obtained by getNPU_statApps)
+ * @param[out] stat The list of request stat
* @note The caller has the responsibility to free the resources.
* This API is not working on the emulated envionment.
*/
-int getNPU_statTasks (npudev_h dev, int appid, npu_stat_tasks *stat);
+int getNPU_statReqs (npudev_h dev, int app_id, npu_stat_reqs *stat);
/**
- * @brief Free the stat instance obtained by getNPU_statTasks().
+ * @brief Free the stat instance obtained by getNPU_statReqs().
* @param[in] stat Stat instance
*/
-void putNPU_statTasks (npu_stat_tasks *stat);
+void putNPU_statReqs (npu_stat_reqs *stat);
#if defined(__cplusplus)
}
/**
* @brief Get the profile information from NPU
- * @param[in] task_id The identifier for each inference
+ * @param[in] req_id The identifier for each inference
* @param[out] profile The profile instance
* @return 0 if no error, otherwise a negative errno.
*/
int
-HostHandler::getProfile (int task_id, npu_profile *profile)
+HostHandler::getProfile (int req_id, npu_profile *profile)
{
- if (task_id < 0 || profile == nullptr) {
+ if (req_id < 0 || profile == nullptr) {
logerr (TAG, "Invalid parameter provided\n");
return -EINVAL;
}
profile->num_layers = 0;
profile->layers = nullptr;
- return profiler_->getTaskProfile (task_id, profile);
+ return profiler_->getProfile (req_id, profile);
}
/**
}
/**
- * @brief get the stats for the latest tasks of the target app
+ * @brief get the stats for the latest reqs of the target app
* @param[in] appid The identifier of target app
- * @param[out] stat The list of task stat
+ * @param[out] stat The list of request stat
* @note The caller has the responsibility to free the resources.
* This API is not working on the emulated envionment.
*/
int
-HostHandler::getStatTasks (int appid, npu_stat_tasks *stat)
+HostHandler::getStatReqs (int appid, npu_stat_reqs *stat)
{
const DriverAPI * api = device_->getDriverAPI ();
assert (api != nullptr);
- return api->getStatTasks (appid, stat);
+ return api->getStatReqs (appid, stat);
}
/**
device_->setAsyncMode (mode);
- int task_id = device_->run (NPUINPUT_HOST, model, input, cb, cb_data, sequence);
- if (task_id > 0)
- profiler_->appendTask (task_id, model);
+ int req_id = device_->run (NPUINPUT_HOST, model, input, cb, cb_data, sequence);
+ if (req_id > 0)
+ profiler_->appendRequest (req_id, model);
- return task_id;
+ return req_id;
}
/**
int getDeviceStatus (npu_status *status, uint32_t *num_requests);
int getStatApps (npu_stat_apps *stat);
- int getStatTasks (int appid, npu_stat_tasks *stat);
+ int getStatReqs (int appid, npu_stat_reqs *stat);
static int getNumDevices (dev_type type);
static int getDevice (npudev_h *dev, dev_type type, uint32_t id);
*/
int
HostInputService::invoke_buffer (const DriverAPI *api, const Model *model,
- Buffer *buffer, outputCallback callback, int task_id)
+ Buffer *buffer, outputCallback callback, int req_id)
{
input_config_t input_config;
device_state_t state;
input_config.dbuf_fd = buffer->getDmabuf ();
input_config.activation_offset_addr0 = buffer->getOffset ();
input_config.activation_offset_addr1 = buffer->getOffset ();
- input_config.task_id = task_id;
+ input_config.req_id = req_id;
/** run the inference with the input */
ret = api->runInput (&input_config);
*/
int
HostInputService::invoke_segt (const DriverAPI *api, const Model *model,
- SegmentTable *segt, outputCallback callback, int task_id)
+ SegmentTable *segt, outputCallback callback, int req_id)
{
input_config_t input_config;
device_state_t state;
input_config.output_mode = OUTPUT_CPU_INTR;
}
- input_config.task_id = task_id;
+ input_config.req_id = req_id;
/** run the inference with the input */
ret = api->runInput (&input_config);
if (ret < 0 && ret != -ECANCELED)
* @param[in] model the target model
* @param[in] data the inference data
* @param[in] callback output callback
- * @return task_id if no error, otherwise a negative errno.
+ * @return req_id if no error, otherwise a negative errno.
*/
int
HwInputService::submit (const DriverAPI *api, int id,
* @param[in] model the target model
* @param[in] segt the target segment table
* @param[in] callback output callback
- * @return task_id if no error, otherwise a negative errno
+ * @return req_id if no error, otherwise a negative errno
*/
int
HwInputService::invoke (const DriverAPI *api, const Model *model,
- SegmentTable *segt, outputCallback callback, int task_id)
+ SegmentTable *segt, outputCallback callback, int req_id)
{
input_config_t input_config;
device_state_t state;
input_config.hw_rdev = devnode_stat.st_rdev;
#else
- input_config.task_id = task_id;
+ input_config.req_id = req_id;
input_config.hw_rdev = 0; /* don't care */
#endif
}
int
-ModelProfiler::appendTask (int task_id, const Model * model)
+ModelProfiler::appendRequest (int req_id, const Model * model)
{
- ProfileData * data = new ProfileData (task_id, model);
- return profile_map_.insert (task_id, data);
+ ProfileData * data = new ProfileData (req_id, model);
+ return profile_map_.insert (req_id, data);
}
int
-ModelProfiler::getTaskProfile (int task_id, npu_profile *profile)
+ModelProfiler::getProfile (int req_id, npu_profile *profile)
{
- ProfileData * data = profile_map_.find (task_id);
+ ProfileData * data = profile_map_.find (req_id);
if (data == nullptr)
return -ENOENT;
if (model == nullptr)
return -EINVAL;
- int status = api_->getProfile (task_id, profile);
+ int status = api_->getProfile (req_id, profile);
if (status != 0)
return status;
if (extended != nullptr)
manipulateProfile (extended, profile);
- profile_map_.remove (task_id);
+ profile_map_.remove (req_id);
return 0;
}
class ProfileData
{
public:
- ProfileData (int task_id, const Model * model) :
- task_id_ (task_id), model_ (model) {}
+ ProfileData (int req_id, const Model * model) :
+ req_id_ (req_id), model_ (model) {}
const Model * getModel () { return model_; }
private:
- int task_id_;
+ int req_id_;
const Model * model_;
};
ModelProfiler (const DriverAPI * api);
~ModelProfiler ();
- int appendTask (int task_id, const Model * model);
- int getTaskProfile (int task_id, npu_profile *profile);
+ int appendRequest (int req_id, const Model * model);
+ int getProfile (int req_id, npu_profile *profile);
void manipulateProfile (HWmem * extended, npu_profile *profile);
* @brief DriverAPI constructor
*/
DriverAPI::DriverAPI (int dev_id) :
- dev_id_ (0), dev_fd_ (-1) /* not opened yet */, initialized_ (false)
+ dev_id_ (dev_id), dev_fd_ (-1) /* not opened yet */, initialized_ (false)
{
}
virtual int getProfile (int task_id, npu_profile *profile) const { return -EPERM; }
virtual int getStatApps (npu_stat_apps *stat) const { return -EPERM; }
- virtual int getStatTasks (int appid, npu_stat_tasks *stat) const { return -EPERM; }
+ virtual int getStatReqs (int appid, npu_stat_reqs *stat) const { return -EPERM; }
protected:
int dev_id_; /**< device id. assume that 0 <= id < getNUmDevices() */
void *addr, size_t size) const;
#endif
- int getProfile (int task_id, npu_profile *profile) const;
+ int getProfile (int req_id, npu_profile *profile) const;
int getStatApps (npu_stat_apps *stat) const;
- int getStatTasks (int appid, npu_stat_tasks *stat) const;
+ int getStatReqs (int appid, npu_stat_reqs *stat) const;
private:
int getDrvVersion () const;
static const std::string dev_node_base;
static std::bitset<CHAR_BIT> dev_bitset;
+ int sched_dev_fd_;
+
std::fstream dev_ios_;
};
/** @brief emulation element */
class EmulElement;
class EmulStat;
-class EmulTask;
+class EmulReq;
/** @brief Driver APIs for emulation */
class TrinityEmulAPI : public DriverAPI {
int registerModel (model_config_t *model, uint64_t npu_version) const;
int deregisterModel (unsigned long long id) const;
- int getProfile (int task_id, npu_profile *profile) const;
- void manipulateProfile (EmulTask *task, npu_profile *profile) const;
+ int getProfile (int req_id, npu_profile *profile) const;
+ void manipulateProfile (EmulReq *req, npu_profile *profile) const;
private:
static std::atomic<int> global_fd_;
/**< dmabuf-to-element map. to track memory allocation */
static ThreadSafeMap<int, EmulStat> stat_map_;
/**< devfd-to-stat map. to track memory statistics */
- static ThreadSafeMap<int, EmulTask> task_map_;
- /**< taskid-to-task map. to support async invoke/stop */
+ static ThreadSafeMap<int, EmulReq> req_map_;
+ /**< reqid-to-req map. to support async invoke/stop */
dev_type dev_type_; /**< emulated device type */
#define DEFAULT_PREFIX_SHARE NE_PREFIX "/share"
#define DEFAULT_PROFILE_PATH "/tmp"
-class EmulTask {
+class EmulReq {
public:
- EmulTask (int taskid) :
- taskid_ (taskid), stop_ (false), first_run_ (false) {}
+ EmulReq (int req_id) :
+ req_id_ (req_id), stop_ (false), first_run_ (false) {}
void run_emul (char *prog, char **segt, char *metadata,
std::string cmd_path, std::string prof_path) {
}
void run (std::function<void ()> func) {
- task_ = std::thread (func);
+ req_ = std::thread (func);
}
void stop () {
stop_ = true;
- task_.join ();
+ req_.join ();
}
bool get_profile (npu_profile *profile) {
std::string path (DEFAULT_PROFILE_PATH);
- path += "/ne_profile." + std::to_string (taskid_) + ".rec";
+ path += "/ne_profile." + std::to_string (req_id_) + ".rec";
std::ifstream ifs (path, std::ios::binary);
if (!ifs.good ()) {
}
private:
- int taskid_;
+ int req_id_;
bool stop_;
bool first_run_;
- std::thread task_;
+ std::thread req_;
};
/**
ThreadSafeMap<int, EmulElement> TrinityEmulAPI::elem_map_;
/** @brief devfd-to-stat map */
ThreadSafeMap<int, EmulStat> TrinityEmulAPI::stat_map_;
-/** @biref taskid-to-task map */
-ThreadSafeMap<int, EmulTask> TrinityEmulAPI::task_map_;
+/** @biref req_id-to-req map */
+ThreadSafeMap<int, EmulReq> TrinityEmulAPI::req_map_;
/** @brief element's global id */
std::atomic<int> EmulElement::global_id_ (0);
/** @brief element's global id */
else
cmd_path += "/mRPsim/triv2.cmd";
- int taskid = input_config->task_id;
- EmulTask *task = new EmulTask (taskid);
+ int req_id = input_config->req_id;
+ EmulReq *req = new EmulReq (req_id);
- status = task_map_.insert (taskid, task);
+ status = req_map_.insert (req_id, req);
if (status != 0) {
delete [] segment_table;
return status;
std::string prof_path (DEFAULT_PROFILE_PATH);
- prof_path += "/ne_profile." + std::to_string (taskid);
+ prof_path += "/ne_profile." + std::to_string (req_id);
- auto func = std::bind (&EmulTask::run_emul, task,
+ auto func = std::bind (&EmulReq::run_emul, req,
prog, segment_table, static_cast <char*> (elem_metadata->getAddr ()),
cmd_path, prof_path);
- task->run (func);
- status = taskid;
+ req->run (func);
+ status = req_id;
if (input_config->input_mode != INPUT_HW)
- task->stop ();
+ req->stop ();
}
return status;
}
int
-TrinityEmulAPI::stop_target (int taskid) const
+TrinityEmulAPI::stop_target (int req_id) const
{
if (!initialized())
return -EPERM;
- EmulTask * task = task_map_.find (taskid);
- if (task == nullptr)
+ EmulReq * req = req_map_.find (req_id);
+ if (req == nullptr)
return -ENOENT;
- task->stop ();
- task_map_.remove (taskid);
+ req->stop ();
+ req_map_.remove (req_id);
return 0;
}
int
-TrinityEmulAPI::getProfile (int taskid, npu_profile *profile) const
+TrinityEmulAPI::getProfile (int req_id, npu_profile *profile) const
{
if (!initialized())
return -EPERM;
- EmulTask * task = task_map_.find (taskid);
- if (task == nullptr)
+ EmulReq * req = req_map_.find (req_id);
+ if (req == nullptr)
return -ENOENT;
- if (!task->get_profile (profile))
+ if (!req->get_profile (profile))
return -EINVAL;
- task_map_.remove (taskid);
+ req_map_.remove (req_id);
return 0;
}
#include <misc/trinity.h>
+#include <misc/npu_sched.h>
+
#include <sys/ioctl.h>
#include <sys/fcntl.h>
#include <sys/mman.h>
* @brief constructor of the API instance for Trinity Vision driver
* @param[in] dev_id device id
*/
-TrinityVision2API::TrinityVision2API (int dev_id) : DriverAPI (dev_id)
+TrinityVision2API::TrinityVision2API (int dev_id) :
+ DriverAPI (dev_id), sched_dev_fd_ (-1)
{
int num_devs;
return;
}
- this->dev_id_ = dev_id;
+ /* Try to open a scheduler device */
+ this->sched_dev_fd_ = ::open ("/dev/npu_sched", O_RDWR);
}
/** @brief destructor of emulation API driver */
TrinityVision2API::~TrinityVision2API ()
{
- if (!(dev_fd_ < 0))
+ if (dev_fd_ >= 0)
::close (dev_fd_);
+ if (sched_dev_fd_ >= 0)
+ ::close (sched_dev_fd_);
}
int
uint32_t num_requests = 0;
for (uint32_t i = 0; i < stat.num_apps; i++)
- num_requests += stat.stat[i].num_active_tasks;
+ num_requests += stat.stat[i].num_active_reqs;
return num_requests;
}
if (!this->initialized())
return -EPERM;
+ if (input_config == nullptr)
+ return -EINVAL;
+
+ if (sched_dev_fd_ > 0) {
+ struct npu_sched_create_task val;
+ struct npu_sched_activate_task val2;
+ uint32_t subtask_id;
+
+ val.task_id = getpid ();
+ val.task_is_rt = false;
+ val.nice_value = input_config->priority;
+ val.num_subtasks = 1; /* FIXME */
+ val.subtask_ids = &subtask_id;
+ subtask_id = input_config->req_id;
+
+ ret = ioctl (sched_dev_fd_, NPU_SCHED_CREATE_TASK, &val);
+ if (ret != 0)
+ return -errno;
+
+ val2.task_handle = val.task_handle;
+ ret = ioctl (sched_dev_fd_, NPU_SCHED_ACTIVATE_TASK, &val2);
+ if (ret != 0)
+ return -errno;
+
+ input_config->task_handle = val.task_handle;
+ }
+
ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_RUN_INPUT,
input_config);
-
if (ret != 0)
return -errno;
- return input_config->task_id;
+ return input_config->req_id;
}
/**
#endif
int
-TrinityVision2API::getProfile (int task_id, npu_profile *profile) const
+TrinityVision2API::getProfile (int req_id, npu_profile *profile) const
{
struct trinity_profile t_profile;
int ret = 0;
if (profile == nullptr)
return -EINVAL;
- t_profile.taskid = task_id;
+ t_profile.req_id = req_id;
ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_GET_PROFILE_META, &t_profile);
if (ret != 0)
strncpy (stat->stat[i].name, stat_app->name, TRINITY_APP_NAME_MAX - 1);
- stat->stat[i].appid = stat_app->appid;
+ stat->stat[i].app_id = stat_app->app_id;
stat->stat[i].status = static_cast<npu_app_status>(stat_app->status);
- stat->stat[i].num_total_tasks = stat_app->num_total_tasks;
- stat->stat[i].num_active_tasks = stat_app->num_active_tasks;
+ stat->stat[i].num_total_reqs = stat_app->num_total_reqs;
+ stat->stat[i].num_active_reqs = stat_app->num_active_reqs;
stat->stat[i].total_alloc_mem = stat_app->total_alloc_mem;
stat->stat[i].total_freed_mem = stat_app->total_freed_mem;
}
int
-TrinityVision2API::getStatTasks (int appid, npu_stat_tasks *stat) const
+TrinityVision2API::getStatReqs (int app_id, npu_stat_reqs *stat) const
{
- struct trinity_ioctl_stat_tasks stat_tasks;
+ struct trinity_ioctl_stat_reqs stat_reqs;
int ret;
if (!this->initialized())
stat->num = 0;
stat->stat = nullptr;
- stat_tasks.appid = appid;
- ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_STAT_TASKS, &stat_tasks);
+ stat_reqs.app_id = app_id;
+ ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_STAT_REQS, &stat_reqs);
if (ret != 0)
return -errno;
- stat->num = stat_tasks.num_tasks;
+ stat->num = stat_reqs.num_reqs;
if (stat->num == 0)
return 0;
- stat->stat = new npu_stat_task[stat->num];
+ stat->stat = new npu_stat_req[stat->num];
for (uint32_t i = 0; i < stat->num; i++) {
- struct trinity_ioctl_stat_task *stat_task = &(stat_tasks.stat[i]);
+ struct trinity_ioctl_stat_req *stat_req = &(stat_reqs.stat[i]);
- stat->stat[i].taskid = stat_task->taskid;
- stat->stat[i].modelid = stat_task->modelid;
+ stat->stat[i].req_id = stat_req->req_id;
+ stat->stat[i].model_id = stat_req->model_id;
- stat->stat[i].priority = static_cast<npu_priority>(stat_task->priority);
- stat->stat[i].status = static_cast<npu_task_status>(stat_task->status);
+ stat->stat[i].priority = static_cast<npu_priority>(stat_req->priority);
+ stat->stat[i].status = static_cast<npu_req_status>(stat_req->status);
- stat->stat[i].sched_time = stat_task->sched_time;
- stat->stat[i].infer_time = stat_task->infer_time;
+ stat->stat[i].sched_time = stat_req->sched_time;
+ stat->stat[i].infer_time = stat_req->infer_time;
}
return 0;
}
/**
- * @brief get the stats for the latest tasks of the target app
+ * @brief get the stats for the latest requests of the target app
* @param[in] dev The NPU device handle
* @param[in] appid The identifier of target app
* @param[out] stat The instance of task stat
* @note The caller has the responsibility to free the resources.
* This API is not working on the emulated envionment.
*/
-int getNPU_statTasks (npudev_h dev, int appid, npu_stat_tasks *stat)
+int getNPU_statReqs (npudev_h dev, int appid, npu_stat_reqs *stat)
{
INIT_HOST_HANDLER (host_handler, dev);
return 0;
#else
- return host_handler->getStatTasks (appid, stat);
+ return host_handler->getStatReqs (appid, stat);
#endif
}
/**
- * @brief Free the stat instance obtained by getNPU_statTasks().
+ * @brief Free the stat instance obtained by getNPU_statReqs().
* @param[in] stat Stat instance
*/
-void putNPU_statTasks (npu_stat_tasks *stat)
+void putNPU_statReqs (npu_stat_reqs *stat)
{
if (stat) {
delete [] stat->stat;
for (i = 0; i < loop_; ++i) {
fprintf (stdout, "[%2u/%2u].......", i + 1, loop_);
usleep(DEFAULT_INTERVAL);
- *ret = ioctl (fd, TRINITY_IOCTL_RUN_INTERNAL_TASK, &rdev);
+ *ret = ioctl (fd, TRINITY_IOCTL_RUN_INTERNAL_REQ, &rdev);
if (*ret != 0) {
fprintf (stdout, "failed\n");
close(fd);
/* without model */
EXPECT_NE (tester.runInternal (0, "/dev/triv2-0"), 0);
- /* TODO: taskid of stop() is currently not checked */
+ /* TODO: reqid of stop() is currently not checked */
#if 0
std::string model_dir (NE_DATADIR);
model_dir += "/testdata/TRIV234_2TOPS/CONV_2D_000";
npu_stat_apps stat_apps;
EXPECT_EQ (getNPU_statApps (dev, &stat_apps), 0);
- npu_stat_tasks stat_tasks;
+ npu_stat_reqs stat_reqs;
#ifdef ENABLE_EMUL
- EXPECT_EQ (getNPU_statTasks (dev, 0, &stat_tasks), 0);
- putNPU_statTasks (&stat_tasks);
+ EXPECT_EQ (getNPU_statReqs (dev, 0, &stat_reqs), 0);
+ putNPU_statReqs (&stat_reqs);
#else
if (stat_apps.stat) {
npu_stat_app *stat_app = stat_apps.stat;
- EXPECT_EQ (getNPU_statTasks (dev, stat_app->appid, &stat_tasks), 0);
- putNPU_statTasks (&stat_tasks);
+ EXPECT_EQ (getNPU_statReqs (dev, stat_app->app_id, &stat_reqs), 0);
+ putNPU_statReqs (&stat_reqs);
}
#endif
EXPECT_NE (getNPU_memoryStatus (dev, nullptr, nullptr), 0);
EXPECT_NE (getNPU_statApps (dev, nullptr), 0);
- EXPECT_NE (getNPU_statTasks (dev, 0, nullptr), 0);
+ EXPECT_NE (getNPU_statReqs (dev, 0, nullptr), 0);
putNPUdevice (dev);
}
int loop ();
void set_device (string node) { node_ = node; }
- void set_appid (string appid) { appid_ = appid; }
+ void set_app_id (string app_id) { app_id_ = app_id; }
void set_interval (string interval) { interval_ = interval; }
static bool signal_exit;
void append_help ();
void append_devices ();
void append_apps ();
- void append_tasks ();
+ void append_reqs ();
string name_;
stringstream ss_;
string help_msg_;
bool help_only_;
- string appid_;
+ string app_id_;
string node_;
string interval_;
};
bool
TrinitySMI::parse_app_id (int & app_id)
{
- const char *nptr = appid_.c_str();
+ const char *nptr = app_id_.c_str();
char *endptr;
errno = 0;
app_id = strtol (nptr, &endptr, 10);
if (errno != 0 || nptr == endptr) {
- ss_ << "| Invalid app id provided: " << left << setw(34) << appid_ << "|\n";
+ ss_ << "| Invalid app id provided: " << left << setw(34) << app_id_ << "|\n";
ss_ << "+------------------------------------------------------------+\n";
return false;
TrinitySMI::append_stats ()
{
if (!node_.empty ()) {
- if (!appid_.empty ()) {
- append_tasks ();
+ if (!app_id_.empty ()) {
+ append_reqs ();
} else {
append_apps ();
}
else
status_str = string ("unknown");
- ss_ << "| " << right << setw(6) << stat->appid << " ";
+ ss_ << "| " << right << setw(6) << stat->app_id << " ";
ss_ << "| " << right << setw(15) << stat->name << " ";
ss_ << "| " << right << setw(10) << status_str << " ";
ss_ << "| " << right << setw(9) << fixed << setprecision(2);
ss_ << (((double) stat->total_alloc_mem) / 1024.0) << " ";
- ss_ << "| " << right << setw(6) << stat->num_total_tasks << " |\n";
+ ss_ << "| " << right << setw(6) << stat->num_total_reqs << " |\n";
count++;
}
ss_ << "+------------------------------------------------------------+\n";
}
-/** @brief show the list of submitted tasks */
+/** @brief show the list of submitted reqs */
void
-TrinitySMI::append_tasks ()
+TrinitySMI::append_reqs ()
{
ss_ << "\n";
ss_ << "+------------------------------------------------------------+\n";
- ss_ << "| TASK ID | MODEL ID | PRIO | STATUS | SCHED | INFER |\n";
+ ss_ << "| req ID | MODEL ID | PRIO | STATUS | SCHED | INFER |\n";
ss_ << "|============================================================|\n";
#ifndef ENABLE_EMUL
uint32_t count = 0;
npudev_h dev;
- npu_stat_tasks stat_tasks;
+ npu_stat_reqs stat_reqs;
if (getNPUdeviceByType (&dev, type, dev_id) != 0)
goto out;
- if (getNPU_statTasks (dev, app_id, &stat_tasks) != 0)
+ if (getNPU_statReqs (dev, app_id, &stat_reqs) != 0)
goto out_free;
- for (uint32_t i = 0; i < stat_tasks.num; i++) {
- npu_stat_task *stat = &(stat_tasks.stat[i]);
+ for (uint32_t i = 0; i < stat_reqs.num; i++) {
+ npu_stat_req *stat = &(stat_reqs.stat[i]);
string priority_str;
string status_str;
else
priority_str = string ("unknown");
- if (stat->status == NPU_TASK_ERROR)
+ if (stat->status == NPU_REQ_ERROR)
status_str = string ("error");
- else if (stat->status == NPU_TASK_PENDING)
+ else if (stat->status == NPU_REQ_PENDING)
status_str = string ("pending");
- else if (stat->status == NPU_TASK_RUNNING)
+ else if (stat->status == NPU_REQ_RUNNING)
status_str = string ("running");
- else if (stat->status == NPU_TASK_FINISHED)
+ else if (stat->status == NPU_REQ_FINISHED)
status_str = string ("finished");
else
status_str = string ("unknown");
- ss_ << "| " << right << setw(7) << stat->taskid << " ";
- ss_ << "| " << right << setw(10) << to_hex_string (stat->modelid) << " ";
+ ss_ << "| " << right << setw(7) << stat->req_id << " ";
+ ss_ << "| " << right << setw(10) << to_hex_string (stat->model_id) << " ";
ss_ << "| " << right << setw(4) << priority_str << " ";
ss_ << "| " << right << setw(8) << status_str << " ";
ss_ << "| " << right << setw(7) << to_string (stat->sched_time) + "ms" << " ";
count++;
}
- putNPU_statTasks (&stat_tasks);
+ putNPU_statReqs (&stat_reqs);
out_free:
putNPUdevice (dev);
out:
if (count == 0)
- ss_ << "| " << left << setw (59) << "No submitted tasks found" << "|\n";
+ ss_ << "| " << left << setw (59) << "No submitted reqs found" << "|\n";
#else
ss_ << "| " << left << setw (59) << "Not supported envionment" << "|\n";
set_device (optarg);
break;
case 'a':
- set_appid (optarg);
+ set_app_id (optarg);
break;
case 'i':
set_interval (optarg);
}
}
- if (!appid_.empty () && node_.empty ()) {
+ if (!app_id_.empty () && node_.empty ()) {
help_msg_ = "\nOption '-a' requires Option '-d' as well, to specify a device node\n";
help_only_ = true;
}