using namespace std;
+typedef enum {
+ AGING_TEST_NONE = 0,
+ AGING_TEST_MODEL,
+ AGING_TEST_INFERENCE,
+ AGING_TEST_MODEL_INFERENCE,
+ AGING_TEST_FULL,
+} AGING_TEST_MODE;
+
#define NPU_TIMEOUT_MS 5000
#define PRINT_STATUS_UNIT 100
#define PRINT_STATUS_ITERS(iter, max) \
/** @brief C++ class to describe how to use npu-engine library */
class Tester : public UtilTRIV2 {
public:
- Tester () : num_iter_ (0), mode_ (0) {}
+ Tester () : tops_ (0), num_iter_ (0), mode_ (AGING_TEST_NONE) {}
/** @brief initilize the device handle */
int init (string model_dir) {
if (meta == nullptr)
return -EINVAL;
- uint32_t tops = NPU_VERSION_TOPS (meta->npu_version);
+ tops_ = NPU_VERSION_TOPS (meta->npu_version);
free (meta);
- int status = UtilTRIV2::init (tops);
- if (status != test_ret_success) {
- cerr << "Failed to initialize\n";
- return status;
- }
-
return 0;
}
uint32_t model_id;
int req_id, status;
- if (mode_ == 0) {
+ status = UtilTRIV2::init (tops_);
+ if (status != test_ret_success) {
+ cerr << "Failed to initialize\n";
+ return status;
+ }
+
+ if (mode_ == AGING_TEST_MODEL) {
/* repeat model_register/unregister */
for (uint32_t i = 0; i < num_iter_; i++) {
PRINT_STATUS_ITERS (i, num_iter_);
check_memleak ();
}
- return test_ret_success;
- } else if (mode_ == 1) {
+
+ status = test_ret_success;
+ } else if (mode_ == AGING_TEST_INFERENCE) {
/* repeat model_inference only */
status = UtilTRIV2::loadModel (model_dir_, &model_id, NPU_PRIORITY_MID,
NPU_TIMEOUT_MS);
return status;
check_memleak ();
- return wait () == num_iter_ ? test_ret_success : test_ret_failure;
- } else if (mode_ == 2) {
+
+ status = wait () == num_iter_ ? test_ret_success : test_ret_failure;
+ } else if (mode_ == AGING_TEST_MODEL_INFERENCE) {
/* repeat model_register/inference/unregister */
for (uint32_t i = 0; i < num_iter_; i++) {
PRINT_STATUS_ITERS (i, num_iter_);
check_memleak ();
}
- return wait () == num_iter_ ? test_ret_success : test_ret_failure;
+ status = wait () == num_iter_ ? test_ret_success : test_ret_failure;
+ } else if (mode_ == AGING_TEST_FULL) {
+ /* repeat whole APIs */
+ for (uint32_t i = 0; i < num_iter_; i++) {
+ PRINT_STATUS_ITERS (i, num_iter_);
+
+ UtilTRIV2::clear ();
+ status = UtilTRIV2::init (tops_);
+ if (status != test_ret_success) {
+ cerr << "Failed to initialize\n";
+ return status;
+ }
+
+ status = UtilTRIV2::loadModel (model_dir_, &model_id, NPU_PRIORITY_MID,
+ NPU_TIMEOUT_MS);
+ if (status != 0)
+ return status;
+
+ req_id = UtilTRIV2::createRequest (model_id);
+ if (req_id < 0)
+ return req_id;
+
+ status = UtilTRIV2::submitRequest (req_id);
+ if (status != 0) {
+ UtilTRIV2::removeRequest (req_id);
+ UtilTRIV2::unloadModel (model_id);
+ return status;
+ }
+
+ status = UtilTRIV2::removeRequest (req_id);
+ if (status != 0) {
+ UtilTRIV2::unloadModel (model_id);
+ return status;
+ }
+
+ status = UtilTRIV2::unloadModel (model_id);
+ if (status != 0)
+ return status;
+
+ check_memleak ();
+ }
+ status = wait () == num_iter_ ? test_ret_success : test_ret_failure;
} else {
- cerr << "Unsupported mode... use 0 (model-only), 1 (fast), or 2 (slow)\n";
- return test_ret_failure;
+ cerr << "Supported mode: 1 (model), 2 (infer), 3 (model/infer), "
+ "or 4 (full)\n";
+ status = test_ret_failure;
}
+
+ UtilTRIV2::clear ();
+ return status;
}
private:
string model_dir_;
+ uint32_t tops_;
uint32_t num_iter_;
uint32_t mode_;
};
/** @brief apptest main */
int
main (int argc, char **argv) {
- const char *help = "model_dir num_iterations test_mode";
+ const char *help = "model_dir test_mode num_iterations";
Tester tester;
int status;
int index;