This patch adds profile data path (.rec) to the profile data struct.
Also, the prefix directory can be set using envvar (NE_PREFIX_PROFILE).
Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
} npu_profile_layer;
typedef struct {
+ char *prof_path; /**< Profile data path (.rec file, if exists) */
uint32_t num_layers;
int64_t total_system_cycles;
* @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.
+ * @note Internal data of npu_profile is valid until putNPU_profile is called
*/
int getNPU_profile (npudev_h dev, int req_id, npu_profile *profile);
profile->num_layers = 0;
profile->layers = nullptr;
+ profile->prof_path = nullptr;
return profiler_->getProfile (req_id, profile);
}
int unregisterModel (uint32_t modelid);
int unregisterModels ();
- int getProfile (int run_id, npu_profile *profile);
+ int getProfile (int req_id, npu_profile *profile);
int getAPILevel (uint32_t *level);
int getTops (uint32_t *tops);
int getDspmSize (uint32_t *dspm);
manipulateProfile (extended, profile);
profile_map_.remove (req_id);
-
return 0;
}
delete [] new_layers;
}
}
-
-
#endif
/** @brief get profile data for vISA instructions */
- virtual int getProfile (int task_id, npu_profile *profile) const { return -EPERM; }
-
+ virtual int getProfile (int req_id, npu_profile *profile) const { return -EPERM; }
virtual int getStatApps (npu_stat_apps *stat) const { return -EPERM; }
virtual int getStatReqs (int appid, npu_stat_reqs *stat) const { return -EPERM; }
dev_type dev_type_; /**< emulated device type */
char *prefix_share_; /**< prefix of share directory */
+ char *prefix_profile_; /**< prefix of profile directory */
};
#endif
#define MAX_EMUL_DEVICES (3)
#define ENV_PREFIX_SHARE "NE_PREFIX_SHARE"
+#define ENV_PREFIX_PROFILE "NE_PREFIX_PROFILE"
#define DEFAULT_PREFIX_SHARE NE_PREFIX "/share"
-#define DEFAULT_PROFILE_PATH "/tmp"
+#define DEFAULT_PREFIX_PROFILE "/tmp"
class EmulReq {
public:
EmulReq (int req_id) :
req_id_ (req_id), stop_ (false), first_run_ (false) {}
+ const char * get_profile_path () const { return prof_path_.c_str (); }
+
void run_emul (char *prog, char **segt, char *metadata,
std::string cmd_path, std::string prof_path) {
first_run_ = true;
+ prof_path_ = prof_path + ".rec";
while (!stop_ || first_run_) {
run_triv2_emul (prog, segt, metadata, cmd_path.c_str (), prof_path.c_str ());
first_run_ = false;
}
bool get_profile (npu_profile *profile) {
- std::string path (DEFAULT_PROFILE_PATH);
- path += "/ne_profile." + std::to_string (req_id_) + ".rec";
-
- std::ifstream ifs (path, std::ios::binary);
+ std::ifstream ifs (prof_path_, std::ios::binary);
if (!ifs.good ()) {
- std::cerr << "Failed to find the profile data " << path << "\n";
+ std::cerr << "Failed to find the profile data " << prof_path_ << "\n";
+ return false;
+ }
+
+ profile->prof_path = strdup (prof_path_.c_str ());
+ if (!profile->prof_path) {
+ std::cerr << "Unable to duplicate the profile path " << prof_path_ << "\n";
return false;
}
bool stop_;
bool first_run_;
std::thread req_;
+ std::string prof_path_;
};
/**
TrinityEmulAPI::TrinityEmulAPI (int dev_id, dev_type type)
: DriverAPI (dev_id), dev_type_ (type)
{
- static char default_prefix[] = DEFAULT_PREFIX_SHARE;
+ static char default_prefix_share[] = DEFAULT_PREFIX_SHARE;
+ static char default_prefix_profile[] = DEFAULT_PREFIX_PROFILE;
prefix_share_ = getenv(ENV_PREFIX_SHARE);
if (prefix_share_ == nullptr) {
- prefix_share_ = default_prefix;
- setenv(ENV_PREFIX_SHARE, default_prefix, 1);
+ prefix_share_ = default_prefix_share;
+ setenv(ENV_PREFIX_SHARE, default_prefix_share, 1);
+ }
+
+ prefix_profile_ = getenv(ENV_PREFIX_PROFILE);
+ if (prefix_profile_ == nullptr) {
+ prefix_profile_ = default_prefix_profile;
+ setenv(ENV_PREFIX_PROFILE, default_prefix_profile, 1);
}
}
return status;
}
- std::string prof_path (DEFAULT_PROFILE_PATH);
+ std::string prof_path (prefix_profile_);
prof_path += "/ne_profile." + std::to_string (req_id);
return -EINVAL;
req_map_.remove (req_id);
-
return 0;
}
if (profile != nullptr) {
delete [] profile->layers;
+ if (profile->prof_path != nullptr)
+ free (profile->prof_path);
+
memset (profile, '\x00', sizeof (npu_profile));
}
}
npu_profile profile;
int status = UtilTRIV2::getProfile (task_id, &profile);
if (status == 0) {
+ if (profile.prof_path != nullptr)
+ cerr << "Profile Path : " << profile.prof_path << "\n";
cerr << "Total System Cycles : " << profile.total_system_cycles << "\n";
if (profile.dram_input_footprint > 0)
cerr << "DRAM Input Footprint (KB) : " << (profile.dram_input_footprint >> 10) << "\n";
}
/** @brief stop inference from run_internal */
-int UtilTrinity::stopInternal (int task_id)
+int UtilTrinity::stopInternal (int req_id)
{
- return stopNPU_internalInput (dev_, task_id);
+ return stopNPU_internalInput (dev_, req_id);
}
/** @brief get profile information from NPU */
-int UtilTrinity::getProfile (int task_id, npu_profile *profile)
+int UtilTrinity::getProfile (int req_id, npu_profile *profile)
{
- return getNPU_profile (dev_, task_id, profile);
+ return getNPU_profile (dev_, req_id, profile);
}
/** @brief configure constraint for the model */
int runAll (bool sync);
int runInternal (uint32_t model_id, std::string dev_path);
- int stopInternal (int task_id);
+ int stopInternal (int req_id);
- int getProfile (int task_id, npu_profile *profile);
+ int getProfile (int req_id, npu_profile *profile);
UtilModel *findModel (uint32_t model_id);