| 50 | |
| 51 | template<typename T> |
| 52 | int wenetEncoderExample(size_t batch_size, size_t num_layers, size_t seq_len, size_t head_num, size_t size_per_head) |
| 53 | { |
| 54 | const size_t hidden_units = head_num * size_per_head; |
| 55 | const size_t d_model = hidden_units; |
| 56 | |
| 57 | const size_t feature_size = 80; |
| 58 | const size_t max_len = 5000; |
| 59 | const size_t inter_size = 2048; |
| 60 | const size_t vocab_size = 4233; |
| 61 | const size_t conv_module_kernel_size = 15; |
| 62 | const int sm = getSMVersion(); |
| 63 | const float q_scaling = 1.0f; |
| 64 | |
| 65 | const size_t kernel_size = 3; |
| 66 | const size_t stride = 2; |
| 67 | const size_t seq_len1 = (seq_len - kernel_size) / stride + 1; |
| 68 | const size_t seq_len2 = (seq_len1 - kernel_size) / stride + 1; |
| 69 | |
| 70 | cudaStream_t stream; |
| 71 | cublasHandle_t cublas_handle; |
| 72 | cublasLtHandle_t cublaslt_handle; |
| 73 | cudnnHandle_t cudnn_handle; |
| 74 | check_cuda_error(cudaStreamCreate(&stream)); |
| 75 | check_cuda_error(cublasCreate(&cublas_handle)); |
| 76 | check_cuda_error(cublasLtCreate(&cublaslt_handle)); |
| 77 | checkCUDNN(cudnnCreate(&cudnn_handle)); |
| 78 | #ifdef SPARSITY_ENABLED |
| 79 | cusparseLtHandle_t cusparselt_handle; |
| 80 | CHECK_CUSPARSE(cusparseLtInit(&cusparselt_handle)); |
| 81 | #endif |
| 82 | check_cuda_error(cublasSetStream(cublas_handle, stream)); |
| 83 | checkCUDNN(cudnnSetStream(cudnn_handle, stream)); |
| 84 | cublasAlgoMap* cublas_algo_map = new cublasAlgoMap("gemm_config.in", ""); |
| 85 | |
| 86 | Allocator<AllocatorType::CUDA> allocator(getDevice()); |
| 87 | |
| 88 | std::mutex* cublas_wrapper_mutex = new std::mutex(); |
| 89 | #ifdef SPARSITY_ENABLED |
| 90 | cublasMMWrapper cublas_wrapper = cublasMMWrapper( |
| 91 | cublas_handle, cublaslt_handle, cusparselt_handle, stream, cublas_algo_map, cublas_wrapper_mutex, &allocator); |
| 92 | #else |
| 93 | cublasMMWrapper cublas_wrapper = |
| 94 | cublasMMWrapper(cublas_handle, cublaslt_handle, stream, cublas_algo_map, cublas_wrapper_mutex, &allocator); |
| 95 | #endif |
| 96 | if (std::is_same<T, half>::value) { |
| 97 | cublas_wrapper.setFP16GemmConfig(); |
| 98 | } |
| 99 | else if (std::is_same<T, float>::value) { |
| 100 | cublas_wrapper.setFP32GemmConfig(); |
| 101 | } |
| 102 | |
| 103 | WenetEncoderWeight<T> wenet_encoder_weights(head_num, |
| 104 | size_per_head, |
| 105 | inter_size, |
| 106 | d_model, |
| 107 | vocab_size, |
| 108 | conv_module_kernel_size, |
| 109 | feature_size, |
nothing calls this directly
no test coverage detected