Skip to content

Commit c83b489

Browse files
[TensorRT] Clip TensorRT code update (#426)
* add trt clip mode in models * add tensorrt sd compile option * add tensorrt clip test code * add tensorrt tokenizer and vocab * tensorrt clip code implement * add trtsd namespace * add tensorrt clip namespace * update trt code * delete useless code * update clip tensorrt test code * update clip class doesn't need threads * update trt clip code to infer dynamic shape --------- Co-authored-by: wangzijian <[email protected]>
1 parent bbeacc8 commit c83b489

File tree

10 files changed

+525393
-4
lines changed

10 files changed

+525393
-4
lines changed

cmake/tensorrt.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,16 @@ file(GLOB TENSORRT_CORE_SRCS ${CMAKE_SOURCE_DIR}/lite/trt/core/*.cpp)
4444
file(GLOB TENSORRT_CV_SRCS ${CMAKE_SOURCE_DIR}/lite/trt/cv/*.cpp)
4545
file(GLOB TENSORRT_NLP_SRCS ${CMAKE_SOURCE_DIR}/lite/trt/nlp/*.cpp)
4646
file(GLOB TENSORRT_ASR_SRCS ${CMAKE_SOURCE_DIR}/lite/trt/asr/*.cpp)
47+
file(GLOB TENSORRT_SD_SRCS ${CMAKE_SOURCE_DIR}/lite/trt/sd/*.cpp)
48+
4749
# 2. glob headers files
4850
file(GLOB TENSORRT_CORE_HEAD ${CMAKE_SOURCE_DIR}/lite/trt/core/*.h)
4951
file(GLOB TENSORRT_CV_HEAD ${CMAKE_SOURCE_DIR}/lite/trt/cv/*.h)
5052
file(GLOB TENSORRT_NLP_HEAD ${CMAKE_SOURCE_DIR}/lite/trt/nlp/*.h)
5153
file(GLOB TENSORRT_ASR_HEAD ${CMAKE_SOURCE_DIR}/lite/trt/asr/*.h)
54+
file(GLOB TENSORRT_SD_HEAD ${CMAKE_SOURCE_DIR}/lite/trt/sd/*.h)
5255

53-
set(TRT_SRCS ${TENSORRT_CV_SRCS} ${TENSORRT_NLP_SRCS} ${TENSORRT_ASR_SRCS} ${TENSORRT_CORE_SRCS})
56+
set(TRT_SRCS ${TENSORRT_CV_SRCS} ${TENSORRT_NLP_SRCS} ${TENSORRT_ASR_SRCS} ${TENSORRT_CORE_SRCS} ${TENSORRT_SD_SRCS})
5457
# 3. copy
5558
message("[Lite.AI.Toolkit][I] Installing Lite.AI.ToolKit Headers for TensorRT Backend ...")
5659
# "INSTALL" can copy all files from the list to the specified path.
@@ -59,3 +62,5 @@ file(INSTALL ${TENSORRT_CORE_HEAD} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/l
5962
file(INSTALL ${TENSORRT_CV_HEAD} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/lite/trt/cv)
6063
file(INSTALL ${TENSORRT_ASR_HEAD} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/lite/trt/asr)
6164
file(INSTALL ${TENSORRT_NLP_HEAD} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/lite/trt/nlp)
65+
file(INSTALL ${TENSORRT_SD_HEAD} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/lite/trt/sd)
66+

examples/lite/sd/test_lite_clip.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,29 @@ static void test_default()
2121
}
2222

2323

24+
static void test_tensorrt()
25+
{
26+
std::string engine_path = "../../../examples/hub/trt/dynamic_text_model_fp32.engine";
27+
28+
lite::trt::sd::text_encoder::Clip *clip = new lite::trt::sd::text_encoder::Clip(engine_path);
29+
30+
std::vector<std::string> input_vector = {"i am not good at cpp","goi ofg go !"};
31+
32+
std::vector<std::vector<float>> output;
33+
34+
clip->inference(input_vector,output);
35+
36+
delete clip;
37+
38+
}
39+
40+
2441

2542
static void test_lite()
2643
{
2744
test_default();
45+
46+
test_tensorrt();
2847
}
2948

3049
int main(__unused int argc, __unused char *argv[])

lite/models.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
#include "lite/trt/cv/trt_yolov8.h"
130130
#include "lite/trt/cv/trt_yolov6.h"
131131
#include "lite/trt/cv/trt_yolov5_blazeface.h"
132+
#include "lite/trt/sd/trt_clip.h"
132133
#endif
133134

134135
// ENABLE_MNN
@@ -714,6 +715,15 @@ namespace lite{
714715
}
715716
}
716717
}
718+
namespace sd
719+
{
720+
721+
typedef trtsd::TRTClip _TRT_Clip;
722+
namespace text_encoder
723+
{
724+
typedef _TRT_Clip Clip;
725+
}
726+
}
717727
}
718728
#endif
719729
}

lite/ort/sd/clip.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@ namespace ortsd
4444
public:
4545
void encode_text(std::vector<std::string> input_text, std::vector<std::vector<int>> &output);
4646

47-
void inference(std::vector<int> input,std::vector<float> &output);
48-
4947
void inference(std::vector<std::string> input,std::vector<std::vector<float>> &output);
5048

51-
Ort::Value transform(const cv::Mat &mat);
5249
};
5350
}
5451

lite/trt/core/trt_core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ namespace trtcv{
2222
using trtcore::BasicTRTHandler;
2323
}
2424

25+
namespace trtsd{
26+
class LITE_EXPORTS TRTClip;
27+
}
28+
2529

2630

2731
#endif //LITE_AI_TOOLKIT_TRT_CORE_H

lite/trt/core/trt_types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ namespace trtcv{
1010
namespace types = lite::types;
1111
}
1212

13+
namespace trtsd{
14+
namespace types = lite::types;
15+
}
16+
17+
1318

1419
#endif //LITE_AI_TOOLKIT_TRT_TYPES_H

0 commit comments

Comments
 (0)