main
h 79 lines 2.17 KB
Raw
1 /*
2 * Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #pragma once
18
19 #include <cuda_bf16.h>
20 #include <cuda_fp16.h>
21
22 #include <torch/headeronly/core/ScalarType.h>
23
24 namespace vllm {
25 namespace tensorrt_llm {
26
27 template <typename DType>
28 struct ElemsPerAccess;
29
30 template <>
31 struct ElemsPerAccess<half> {
32 static constexpr int value = 8;
33 using vec_type = float4;
34 };
35
36 template <>
37 struct ElemsPerAccess<nv_bfloat16> {
38 static constexpr int value = 8;
39 using vec_type = float4;
40 };
41
42 template <>
43 struct ElemsPerAccess<float> {
44 static constexpr int value = 4;
45 using vec_type = float4;
46 };
47
48 template <typename DType>
49 static constexpr int kElemsPerAccess = ElemsPerAccess<DType>::value;
50
51 struct MiniMaxReduceRMSParams {
52 int nranks{};
53 int rank{};
54 torch::headeronly::ScalarType dtype{torch::headeronly::ScalarType::Undefined};
55 int size_q{};
56 int hidden_dim{};
57 int size_k{};
58 int hidden_dim_k{};
59 int stride_q{}; // row stride for q input (elements); when > hidden_dim,
60 // q is part of a wider qkv tensor
61 int stride_k{}; // row stride for k input (elements); when > hidden_dim_k,
62 // k is part of a wider qkv tensor
63 int stride_q_out{}; // row stride for q output (elements); 0 = contiguous
64 int stride_k_out{}; // row stride for k output (elements); 0 = contiguous
65 void** workspace{};
66 void* allreduce_in{};
67 void* rms_norm_out{};
68 void* rms_gamma{};
69 void* allreduce_in_k{};
70 void* rms_norm_out_k{};
71 void* rms_gamma_k{};
72 float rms_eps{};
73 cudaStream_t stream{};
74 };
75
76 void minimax_reduce_rms_op(MiniMaxReduceRMSParams const& params);
77
78 } // namespace tensorrt_llm
79 } // namespace vllm