From 6e37612b61094e0ab08b38d35f588c2b17eae267 Mon Sep 17 00:00:00 2001
From: lyblsgo <lyblsgo@163.com>
Date: 星期二, 11 四月 2023 19:53:34 +0800
Subject: [PATCH] c++ grpc&onnxruntime support multi threads
---
funasr/runtime/onnxruntime/tester/tester_rtf.cpp | 65 ++++++++++++++++++++------------
1 files changed, 40 insertions(+), 25 deletions(-)
diff --git a/funasr/runtime/onnxruntime/tester/tester_rtf.cpp b/funasr/runtime/onnxruntime/tester/tester_rtf.cpp
index 131ca64..ca17e50 100644
--- a/funasr/runtime/onnxruntime/tester/tester_rtf.cpp
+++ b/funasr/runtime/onnxruntime/tester/tester_rtf.cpp
@@ -5,30 +5,13 @@
#include <win_func.h>
#endif
-#include "librapidasrapi.h"
+#include "libfunasrapi.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
-#include <thread>
using namespace std;
-
-void runReg(vector<string> wav_list, RPASR_HANDLE AsrHanlde)
-{
- for (size_t i = 0; i < wav_list.size(); i++)
- {
- RPASR_RESULT Result=RapidAsrRecogFile(AsrHanlde, wav_list[i].c_str(), RASR_NONE, NULL);
-
- if(Result){
- string msg = RapidAsrGetResult(Result, 0);
- printf("Result: %s \n", msg.c_str());
- RapidAsrFreeResult(Result);
- }else{
- cout <<"No return data!";
- }
- }
-}
int main(int argc, char *argv[])
{
@@ -64,21 +47,53 @@
bool quantize = false;
istringstream(argv[3]) >> boolalpha >> quantize;
- RPASR_HANDLE AsrHanlde=RapidAsrInit(argv[1], nThreadNum, quantize);
+ FUNASR_HANDLE AsrHanlde=FunASRInit(argv[1], nThreadNum, quantize);
if (!AsrHanlde)
{
printf("Cannot load ASR Model from: %s, there must be files model.onnx and vocab.txt", argv[1]);
exit(-1);
}
+ gettimeofday(&end, NULL);
+ long seconds = (end.tv_sec - start.tv_sec);
+ long modle_init_micros = ((seconds * 1000000) + end.tv_usec) - (start.tv_usec);
+ printf("Model initialization takes %lfs.\n", (double)modle_init_micros / 1000000);
+
+ // warm up
+ for (size_t i = 0; i < 30; i++)
+ {
+ FUNASR_RESULT Result=FunASRRecogFile(AsrHanlde, wav_list[0].c_str(), RASR_NONE, NULL);
+ }
+
+ // forward
+ float snippet_time = 0.0f;
+ float total_length = 0.0f;
+ long total_time = 0.0f;
- std::thread t1(runReg, wav_list, AsrHanlde);
- std::thread t2(runReg, wav_list, AsrHanlde);
+ for (size_t i = 0; i < wav_list.size(); i++)
+ {
+ gettimeofday(&start, NULL);
+ FUNASR_RESULT Result=FunASRRecogFile(AsrHanlde, wav_list[i].c_str(), RASR_NONE, NULL);
+ gettimeofday(&end, NULL);
+ seconds = (end.tv_sec - start.tv_sec);
+ long taking_micros = ((seconds * 1000000) + end.tv_usec) - (start.tv_usec);
+ total_time += taking_micros;
- t1.join();
- t2.join();
+ if(Result){
+ string msg = FunASRGetResult(Result, 0);
+ printf("Result: %s \n", msg);
- //runReg(wav_list, AsrHanlde);
+ snippet_time = FunASRGetRetSnippetTime(Result);
+ total_length += snippet_time;
+ FunASRFreeResult(Result);
+ }else{
+ cout <<"No return data!";
+ }
+ }
- RapidAsrUninit(AsrHanlde);
+ printf("total_time_wav %ld ms.\n", (long)(total_length * 1000));
+ printf("total_time_comput %ld ms.\n", total_time / 1000);
+ printf("total_rtf %05lf .\n", (double)total_time/ (total_length*1000000));
+
+ FunASRUninit(AsrHanlde);
return 0;
}
--
Gitblit v1.9.1