MCPcopy Create free account
hub / github.com/NVIDIA/FasterTransformer / test

Function test

examples/cpp/vit_int8/vit_int8_example.cc:29–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27
28template<typename T>
29void test(int batch_size,
30 int img_size,
31 int patch_size,
32 int embed_dim,
33 int head_num,
34 int layer_num,
35 int int8_mode,
36 int has_cls_token)
37{
38 cudnnHandle_t cudnn_handle;
39 cublasHandle_t cublas_handle;
40 cublasLtHandle_t cublaslt_handle;
41 cudaStream_t stream = 0;
42 checkCUDNN(cudnnCreate(&cudnn_handle));
43 checkCUDNN(cudnnSetStream(cudnn_handle, stream));
44 check_cuda_error(cublasCreate(&cublas_handle));
45 check_cuda_error(cublasSetStream(cublas_handle, stream));
46 check_cuda_error(cublasLtCreate(&cublaslt_handle));
47
48 cublasAlgoMap* cublas_algo_map = new cublasAlgoMap("igemm_config.in");
49
50 int sm = getSMVersion();
51
52 std::mutex* cublas_wrapper_mutex = new std::mutex();
53
54 bool use_ORDER_COL32_2R_4R4 = false;
55#if (CUDART_VERSION >= 11000)
56 if (sm >= 80) {
57 use_ORDER_COL32_2R_4R4 = true;
58 }
59#endif
60
61 cublasINT8MMWrapper* cublas_wrapper = new cublasINT8MMWrapper(
62 cublas_handle, cublaslt_handle, stream, cublas_algo_map, cublas_wrapper_mutex, use_ORDER_COL32_2R_4R4);
63
64 if (std::is_same<T, half>::value) {
65 cublas_wrapper->setFP16GemmConfig();
66 }
67 else if (std::is_same<T, float>::value) {
68 cublas_wrapper->setFP32GemmConfig();
69 }
70 const int in_chans = 3;
71 const int inter_size = embed_dim * 4;
72 const int head_dim = embed_dim / head_num;
73 const bool with_cls_token = has_cls_token > 0;
74 const int seq_len = (img_size / patch_size) * (img_size / patch_size) + (with_cls_token ? 1 : 0);
75
76 ViTINT8Weight<T> params =
77 ViTINT8Weight<T>(embed_dim, inter_size, layer_num, img_size, patch_size, in_chans, with_cls_token);
78
79 FT_LOG_INFO("batch_size: %d, img_size : %d,\n"
80 "patch_size: %d, embed_dim: %d,\n"
81 "head_num : %d, head_dim : %d,\n"
82 "layer_num : %d, seq_len : %d,\n"
83 "inter_size:%d\n",
84 batch_size,
85 img_size,
86 patch_size,

Callers

nothing calls this directly

Calls 6

getSMVersionFunction · 0.85
setFP16GemmConfigMethod · 0.80
setFP32GemmConfigMethod · 0.80
forwardMethod · 0.45
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected