| 27 | |
| 28 | template<typename T> |
| 29 | void test( |
| 30 | int batch_size, int img_size, int patch_size, int embed_dim, int head_num, int layer_num, int token_classifier) |
| 31 | { |
| 32 | cudnnHandle_t cudnn_handle; |
| 33 | cublasHandle_t cublas_handle; |
| 34 | cublasLtHandle_t cublaslt_handle; |
| 35 | cudaStream_t stream = 0; |
| 36 | checkCUDNN(cudnnCreate(&cudnn_handle)); |
| 37 | checkCUDNN(cudnnSetStream(cudnn_handle, stream)); |
| 38 | check_cuda_error(cublasCreate(&cublas_handle)); |
| 39 | check_cuda_error(cublasSetStream(cublas_handle, stream)); |
| 40 | check_cuda_error(cublasLtCreate(&cublaslt_handle)); |
| 41 | |
| 42 | cublasAlgoMap* cublas_algo_map = new cublasAlgoMap("gemm_config.in"); |
| 43 | |
| 44 | std::mutex* cublas_wrapper_mutex = new std::mutex(); |
| 45 | |
| 46 | cublasMMWrapper* cublas_wrapper = |
| 47 | new cublasMMWrapper(cublas_handle, cublaslt_handle, stream, cublas_algo_map, cublas_wrapper_mutex, nullptr); |
| 48 | |
| 49 | if (std::is_same<T, half>::value) { |
| 50 | cublas_wrapper->setFP16GemmConfig(); |
| 51 | } |
| 52 | else if (std::is_same<T, float>::value) { |
| 53 | cublas_wrapper->setFP32GemmConfig(); |
| 54 | } |
| 55 | const int in_chans = 3; |
| 56 | const bool with_cls_token = token_classifier > 0; |
| 57 | const int inter_size = embed_dim * 4; |
| 58 | const int head_dim = embed_dim / head_num; |
| 59 | const int seq_len = (img_size / patch_size) * (img_size / patch_size) + (with_cls_token ? 1 : 0); |
| 60 | |
| 61 | ViTWeight<T> params = |
| 62 | ViTWeight<T>(embed_dim, inter_size, layer_num, img_size, patch_size, in_chans, with_cls_token); |
| 63 | |
| 64 | FT_LOG_INFO("batch_size: %d, img_size : %d,\n" |
| 65 | "patch_size: %d, embed_dim: %d,\n" |
| 66 | "head_num : %d, head_dim : %d,\n" |
| 67 | "layer_num : %d, seq_len : %d,\n" |
| 68 | "inter_size:%d\n", |
| 69 | batch_size, |
| 70 | img_size, |
| 71 | patch_size, |
| 72 | embed_dim, |
| 73 | head_num, |
| 74 | head_dim, |
| 75 | layer_num, |
| 76 | seq_len, |
| 77 | inter_size); |
| 78 | |
| 79 | AttentionType attention_type = getAttentionType<T>(head_dim, getSMVersion(), true, seq_len); |
| 80 | printf("Attention Type: %d\n", int(attention_type)); |
| 81 | fastertransformer::Allocator<AllocatorType::CUDA> allocator(0); |
| 82 | int max_batch = batch_size; |
| 83 | ViTTransformer<T>* vit = new ViTTransformer<T>(max_batch, |
| 84 | img_size, |
| 85 | in_chans, |
| 86 | patch_size, |
nothing calls this directly
no test coverage detected