| 57 | |
| 58 | template<typename T> |
| 59 | int xlnetExample(size_t batch_size, size_t num_layers, size_t seq_len, size_t head_num, size_t size_per_head) |
| 60 | { |
| 61 | printf("[INFO] Device: %s \n", getDeviceName().c_str()); |
| 62 | |
| 63 | const size_t hidden_units = head_num * size_per_head; |
| 64 | const size_t inter_size = 4 * hidden_units; |
| 65 | |
| 66 | cudaStream_t stream; |
| 67 | cublasHandle_t cublas_handle; |
| 68 | cublasLtHandle_t cublaslt_handle; |
| 69 | cudaStreamCreate(&stream); |
| 70 | cublasCreate(&cublas_handle); |
| 71 | cublasLtCreate(&cublaslt_handle); |
| 72 | |
| 73 | cublasSetStream(cublas_handle, stream); |
| 74 | cublasAlgoMap* cublas_algo_map = new cublasAlgoMap("gemm_config.in", ""); |
| 75 | |
| 76 | Allocator<AllocatorType::CUDA> allocator(getDevice()); |
| 77 | |
| 78 | std::mutex* cublas_wrapper_mutex = new std::mutex(); |
| 79 | |
| 80 | cublasMMWrapper cublas_wrapper = |
| 81 | cublasMMWrapper(cublas_handle, cublaslt_handle, stream, cublas_algo_map, cublas_wrapper_mutex, &allocator); |
| 82 | |
| 83 | if (std::is_same<T, half>::value) { |
| 84 | cublas_wrapper.setFP16GemmConfig(); |
| 85 | } |
| 86 | #ifdef ENABLE_BF16 |
| 87 | else if (std::is_same<T, __nv_bfloat16>::value) { |
| 88 | cublas_wrapper.setBF16GemmConfig(); |
| 89 | } |
| 90 | #endif |
| 91 | else if (std::is_same<T, float>::value) { |
| 92 | cublas_wrapper.setFP32GemmConfig(); |
| 93 | } |
| 94 | |
| 95 | // Set layer weight |
| 96 | std::vector<XlnetLayerWeight<T>> xlnet_layer_weights(num_layers, XlnetLayerWeight<T>(hidden_units, inter_size)); |
| 97 | |
| 98 | // Allocate Input & Output |
| 99 | T* word_emb_k; |
| 100 | deviceMalloc(&word_emb_k, batch_size * seq_len * hidden_units, false); |
| 101 | float* input_mask; |
| 102 | deviceMalloc(&input_mask, batch_size * seq_len, false); |
| 103 | int* seg_id; |
| 104 | deviceMalloc(&seg_id, batch_size * seq_len, false); |
| 105 | |
| 106 | T* out_tensor; |
| 107 | deviceMalloc(&out_tensor, batch_size * seq_len * hidden_units, false); |
| 108 | |
| 109 | std::vector<Tensor> input_tensors = std::vector<Tensor>{ |
| 110 | Tensor{MEMORY_GPU, getTensorType<T>(), std::vector<size_t>{batch_size, seq_len, hidden_units}, word_emb_k}, |
| 111 | Tensor{MEMORY_GPU, getTensorType<float>(), std::vector<size_t>{batch_size, seq_len}, input_mask}, |
| 112 | Tensor{MEMORY_GPU, getTensorType<int>(), std::vector<size_t>{batch_size, seq_len}, seg_id}}; |
| 113 | |
| 114 | std::vector<Tensor> output_tensors = std::vector<Tensor>{ |
| 115 | Tensor{MEMORY_GPU, getTensorType<T>(), std::vector<size_t>{batch_size, seq_len, hidden_units}, out_tensor}}; |
| 116 |
nothing calls this directly
no test coverage detected