[Fix] Rename 'task' to 'request'
authorDongju Chae <dongju.chae@samsung.com>
Fri, 26 Mar 2021 11:15:37 +0000 (20:15 +0900)
committer채동주/On-Device Lab(SR)/Staff Engineer/삼성전자 <dongju.chae@samsung.com>
Thu, 8 Apr 2021 06:26:56 +0000 (15:26 +0900)
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>
16 files changed:
include/common/typedef.h
include/host/libnpuhost.h
src/core/ne-handler.cc
src/core/ne-handler.h
src/core/ne-host-input-service.cc
src/core/ne-hw-input-service.cc
src/core/ne-profiler.cc
src/core/ne-profiler.h
src/core/npu/NPUdrvAPI.cc
src/core/npu/NPUdrvAPI.h
src/core/npu/NPUdrvAPI_emul.cc
src/core/npu/NPUdrvAPI_triv2.cc
src/host/ne-host.cc
tests/apptests/tvn_triv2_recurring.cc
tests/unittests/ne_libnpuhost_test.cc
utils/trinity_smi/trinity-smi.cc

index 24bfc43..c1c095f 100644 (file)
@@ -189,9 +189,9 @@ typedef enum {
  *          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;
 
@@ -273,24 +273,24 @@ typedef enum {
 } 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;
@@ -302,20 +302,20 @@ typedef struct {
 } 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)
index 107014a..fc2d01f 100644 (file)
@@ -128,14 +128,14 @@ npubin_meta * getNPUmodel_metadata(const char *model, bool need_extra);
  * @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
@@ -144,7 +144,7 @@ int registerNPUmodel(npudev_h dev, generic_buffer *modelfile, uint32_t *modelid)
  * @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
@@ -156,29 +156,29 @@ int unregisterNPUmodel_all(npudev_h dev);
 /**
  * @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
@@ -186,19 +186,19 @@ int setNPU_constraint(npudev_h dev, uint32_t modelid, npuConstraint constraint);
  * @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);
 
 /**
@@ -212,7 +212,7 @@ int stopNPU_internalInput(npudev_h dev, int id);
 /**
  * @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.
@@ -220,7 +220,7 @@ int stopNPU_internalInput(npudev_h dev, int id);
  * @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);
 
@@ -372,11 +372,11 @@ int cleanNPU_genericBuffers (npudev_h dev, generic_buffers * buffers);
 /**
  * @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().
@@ -402,20 +402,20 @@ int getNPU_statApps (npudev_h dev, npu_stat_apps *stat);
 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)
 }
index 260fca9..f01002e 100644 (file)
@@ -123,14 +123,14 @@ HostHandler::unregisterModels ()
 
 /**
  * @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;
   }
@@ -138,7 +138,7 @@ HostHandler::getProfile (int task_id, npu_profile *profile)
   profile->num_layers = 0;
   profile->layers = nullptr;
 
-  return profiler_->getTaskProfile (task_id, profile);
+  return profiler_->getProfile (req_id, profile);
 }
 
 /**
@@ -157,19 +157,19 @@ HostHandler::getStatApps (npu_stat_apps *stat)
 }
 
 /**
- * @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);
 }
 
 /**
@@ -348,11 +348,11 @@ HostHandler::runAsync (uint32_t modelid, const input_buffers *input,
 
   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;
 }
 
 /**
index f9fa4f6..91a809d 100644 (file)
@@ -64,7 +64,7 @@ class HostHandler {
     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);
index ddc2178..7c67c85 100644 (file)
@@ -111,7 +111,7 @@ HostInputService::remove (int 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;
@@ -141,7 +141,7 @@ HostInputService::invoke_buffer (const DriverAPI *api, const Model *model,
   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);
@@ -167,7 +167,7 @@ handle_callback:
  */
 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;
@@ -209,7 +209,7 @@ HostInputService::invoke_segt (const DriverAPI *api, const Model *model,
     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)
index ac5b17b..a5fe299 100644 (file)
@@ -37,7 +37,7 @@ HwInputService::getInstance ()
  * @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,
@@ -59,11 +59,11 @@ 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;
@@ -131,7 +131,7 @@ HwInputService::invoke (const DriverAPI *api, const Model *model,
 
   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
 
index 98d5f15..3c76413 100644 (file)
@@ -24,16 +24,16 @@ ModelProfiler::~ModelProfiler ()
 }
 
 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;
 
@@ -41,7 +41,7 @@ ModelProfiler::getTaskProfile (int task_id, npu_profile *profile)
   if (model == nullptr)
     return -EINVAL;
 
-  int status = api_->getProfile (task_id, profile);
+  int status = api_->getProfile (req_id, profile);
   if (status != 0)
     return status;
 
@@ -49,7 +49,7 @@ ModelProfiler::getTaskProfile (int task_id, npu_profile *profile)
   if (extended != nullptr)
     manipulateProfile (extended, profile);
 
-  profile_map_.remove (task_id);
+  profile_map_.remove (req_id);
 
   return 0;
 }
index 3e3bd97..4f6fc53 100644 (file)
 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_;
 };
 
@@ -36,8 +36,8 @@ class ModelProfiler
     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);
 
index 44f8cb2..73cb4a1 100644 (file)
@@ -25,7 +25,7 @@ uint32_t DriverAPI::api_level_ = TRINITY_API_LEVEL;
  * @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)
 {
 }
 
index a251e63..1707df0 100644 (file)
@@ -112,7 +112,7 @@ class DriverAPI {
     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() */
@@ -161,16 +161,18 @@ class TrinityVision2API : public DriverAPI {
         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_;
 };
 
@@ -179,7 +181,7 @@ class TrinityVision2API : public DriverAPI {
 /** @brief emulation element */
 class EmulElement;
 class EmulStat;
-class EmulTask;
+class EmulReq;
 
 /** @brief Driver APIs for emulation */
 class TrinityEmulAPI : public DriverAPI {
@@ -206,8 +208,8 @@ 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_;
@@ -216,8 +218,8 @@ class TrinityEmulAPI : public DriverAPI {
       /**< 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 */
 
index 1bc6567..dc1c5aa 100644 (file)
 #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) {
@@ -48,17 +48,17 @@ class EmulTask {
     }
 
     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 ()) {
@@ -171,10 +171,10 @@ class EmulTask {
     }
 
   private:
-    int taskid_;
+    int req_id_;
     bool stop_;
     bool first_run_;
-    std::thread task_;
+    std::thread req_;
 };
 
 /**
@@ -274,8 +274,8 @@ EmulElement::EmulElement (size_t size)
 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 */
@@ -607,10 +607,10 @@ TrinityEmulAPI::runInput (input_config_t *input_config) const
     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;
@@ -618,17 +618,17 @@ TrinityEmulAPI::runInput (input_config_t *input_config) const
 
     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;
@@ -657,35 +657,35 @@ TrinityEmulAPI::stop () const
 }
 
 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;
 }
index eccbc5a..1193114 100644 (file)
@@ -1,4 +1,6 @@
 #include <misc/trinity.h>
+#include <misc/npu_sched.h>
+
 #include <sys/ioctl.h>
 #include <sys/fcntl.h>
 #include <sys/mman.h>
@@ -21,7 +23,8 @@ std::bitset<CHAR_BIT> TrinityVision2API::dev_bitset = 0;
  * @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;
 
@@ -39,14 +42,17 @@ TrinityVision2API::TrinityVision2API (int dev_id) : DriverAPI (dev_id)
     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
@@ -153,7 +159,7 @@ TrinityVision2API::numRequests () const
       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;
     }
@@ -353,13 +359,39 @@ TrinityVision2API::runInput (input_config_t *input_config) const
   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;
 }
 
 /**
@@ -437,7 +469,7 @@ TrinityVision2API::fpga_memcpy (int dmabuf, uint32_t offset, void *addr, size_t
 #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;
@@ -445,7 +477,7 @@ TrinityVision2API::getProfile (int task_id, npu_profile *profile) const
   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)
@@ -556,11 +588,11 @@ TrinityVision2API::getStatApps (npu_stat_apps *stat) const
 
     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;
@@ -570,9 +602,9 @@ TrinityVision2API::getStatApps (npu_stat_apps *stat) const
 }
 
 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())
@@ -584,28 +616,28 @@ TrinityVision2API::getStatTasks (int appid, npu_stat_tasks *stat) const
   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;
index 32174e2..fb1b5c2 100644 (file)
@@ -241,14 +241,14 @@ 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
  * @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);
 
@@ -263,15 +263,15 @@ int getNPU_statTasks (npudev_h dev, int appid, npu_stat_tasks *stat)
 
   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;
index 3c06ccc..1f210de 100644 (file)
@@ -166,7 +166,7 @@ class TesterTRIV2 {
       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);
index 72923e8..e607a59 100644 (file)
@@ -273,7 +273,7 @@ TEST (ne_libnpuhost_test, run_internal_triv2_binfmt_v3_n)
   /* 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";
@@ -753,16 +753,16 @@ TEST (ne_libnpuhost_test, statistics_apis)
   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
 
@@ -785,7 +785,7 @@ TEST (ne_libnpuhost_test, statistics_apis_n)
 
   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);
 }
index 77bbf3f..497511a 100644 (file)
@@ -53,7 +53,7 @@ class TrinitySMI {
     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;
@@ -67,7 +67,7 @@ class TrinitySMI {
     void append_help ();
     void append_devices ();
     void append_apps ();
-    void append_tasks ();
+    void append_reqs ();
 
     string name_;
     stringstream ss_;
@@ -75,7 +75,7 @@ class TrinitySMI {
     string help_msg_;
     bool help_only_;
 
-    string appid_;
+    string app_id_;
     string node_;
     string interval_;
 };
@@ -143,14 +143,14 @@ TrinitySMI::parse_device_node (dev_type & type, int & dev_id)
 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;
@@ -216,8 +216,8 @@ void
 TrinitySMI::append_stats ()
 {
   if (!node_.empty ()) {
-    if (!appid_.empty ()) {
-      append_tasks ();
+    if (!app_id_.empty ()) {
+      append_reqs ();
     } else {
       append_apps ();
     }
@@ -344,12 +344,12 @@ TrinitySMI::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++;
   }
 
@@ -367,13 +367,13 @@ out:
   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
@@ -388,16 +388,16 @@ TrinitySMI::append_tasks ()
 
   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;
 
@@ -410,19 +410,19 @@ TrinitySMI::append_tasks ()
     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" << " ";
@@ -430,13 +430,13 @@ TrinitySMI::append_tasks ()
     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";
@@ -552,7 +552,7 @@ TrinitySMI::check_arguments (int argc, char ** argv)
         set_device (optarg);
         break;
       case 'a':
-        set_appid (optarg);
+        set_app_id (optarg);
         break;
       case 'i':
         set_interval (optarg);
@@ -573,7 +573,7 @@ TrinitySMI::check_arguments (int argc, char ** argv)
     }
   }
 
-  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;
   }