Skip to content

Commit 14a302c

Browse files
committed
pre-commit run
Signed-off-by: Harry Zhou <hhanyu@nvidia.com>
1 parent a8a2cfa commit 14a302c

3 files changed

Lines changed: 28 additions & 26 deletions

File tree

transformer_engine/common/fused_router/async_loader.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ inline int choose_num_buffers(size_t single_buf_shmem, size_t other_shmem_bytes)
6464
NVTE_CHECK_CUDA(cudaDeviceGetAttribute(&max_smem_per_sm,
6565
cudaDevAttrMaxSharedMemoryPerMultiprocessor, device_id));
6666

67-
int blocks_double =
68-
(total_double > 0) ? static_cast<int>(max_smem_per_sm / total_double) : 0;
69-
int blocks_single =
70-
(total_single > 0) ? static_cast<int>(max_smem_per_sm / total_single) : 0;
67+
int blocks_double = (total_double > 0) ? static_cast<int>(max_smem_per_sm / total_double) : 0;
68+
int blocks_single = (total_single > 0) ? static_cast<int>(max_smem_per_sm / total_single) : 0;
7169

7270
if (blocks_double >= kMinBlocksPerSM) return 2;
7371
if (blocks_single >= kMinBlocksPerSM) return 1;

transformer_engine/common/fused_router/fused_score_for_moe_aux_loss.cu

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
************************************************************************/
66

77
#include <assert.h>
8-
#include <climits>
98
#include <cuda_runtime.h>
109
#include <transformer_engine/fused_router.h>
1110

11+
#include <climits>
12+
1213
#include "../common.h"
1314
#include "../util/logging.h"
1415
#include "../utils.cuh"
@@ -24,9 +25,11 @@ namespace fused_router {
2425
// =============================================================================
2526

2627
template <typename DataType, TopkFuncType TopkFunc = TopkFuncType::Naive>
27-
__global__ void fused_score_for_moe_aux_loss_forward_simple_kernel(
28-
const DataType *logits, int num_tokens, int num_experts, int topk, int score_function,
29-
float *scores, bool *routing_map, CompType *intermediate_output) {
28+
__global__ void fused_score_for_moe_aux_loss_forward_simple_kernel(const DataType *logits,
29+
int num_tokens, int num_experts,
30+
int topk, int score_function,
31+
float *scores, bool *routing_map,
32+
CompType *intermediate_output) {
3033
int num_token_per_block = blockDim.x / kThreadsPerWarp;
3134
int warp_id = threadIdx.x / kThreadsPerWarp;
3235
int lane_id = threadIdx.x % kThreadsPerWarp;
@@ -299,8 +302,8 @@ void fused_score_for_moe_aux_loss_forward_kernel_launcher(
299302
check_shared_memory_capacity_num_experts(other_shmem, num_experts);
300303

301304
auto launch_simple = [&](auto kernel) {
302-
NVTE_CHECK_CUDA(cudaFuncSetAttribute(kernel, cudaFuncAttributeMaxDynamicSharedMemorySize,
303-
other_shmem));
305+
NVTE_CHECK_CUDA(
306+
cudaFuncSetAttribute(kernel, cudaFuncAttributeMaxDynamicSharedMemorySize, other_shmem));
304307
kernel<<<total_blocks, kThreadsPerBlock, other_shmem, stream>>>(
305308
logits, num_tokens, num_experts, topk, score_function, scores, routing_map,
306309
intermediate_output);

transformer_engine/common/fused_router/fused_topk_with_score_function.cu

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
************************************************************************/
66

77
#include <assert.h>
8-
#include <climits>
98
#include <cuda_runtime.h>
109
#include <transformer_engine/fused_router.h>
1110

11+
#include <climits>
12+
1213
#include "../common.h"
1314
#include "../util/logging.h"
1415
#include "async_loader.h"
@@ -24,11 +25,12 @@ namespace fused_router {
2425
// =============================================================================
2526

2627
template <typename DataType, typename BiasType, TopkFuncType TopkFunc = TopkFuncType::Naive>
27-
__global__ void fused_topk_forward_simple_kernel(
28-
const DataType *logits, int num_tokens, int num_experts, int topk, bool use_pre_softmax,
29-
int num_groups, int group_topk, float scaling_factor, int score_function,
30-
const BiasType *expert_bias, DataType *probs, bool *routing_map,
31-
CompType *intermediate_output) {
28+
__global__ void fused_topk_forward_simple_kernel(const DataType *logits, int num_tokens,
29+
int num_experts, int topk, bool use_pre_softmax,
30+
int num_groups, int group_topk,
31+
float scaling_factor, int score_function,
32+
const BiasType *expert_bias, DataType *probs,
33+
bool *routing_map, CompType *intermediate_output) {
3234
int num_token_per_block = blockDim.x / kThreadsPerWarp;
3335
int warp_id = threadIdx.x / kThreadsPerWarp;
3436
int lane_id = threadIdx.x % kThreadsPerWarp;
@@ -112,9 +114,8 @@ __global__ void fused_topk_forward_simple_kernel(
112114
if (group_topk > 0) {
113115
int group_size = num_experts / num_groups;
114116
for (int i = 0; i < num_groups; i++) {
115-
topk_and_mask<TopkFunc>(
116-
scores + i * group_size, group_size, topk / group_topk,
117-
topk_indices, topk_scores, lane_id);
117+
topk_and_mask<TopkFunc>(scores + i * group_size, group_size, topk / group_topk,
118+
topk_indices, topk_scores, lane_id);
118119
__syncwarp();
119120
if (lane_id == 0) {
120121
CompType tmp = 0.0;
@@ -125,8 +126,8 @@ __global__ void fused_topk_forward_simple_kernel(
125126
}
126127
__syncwarp();
127128
}
128-
topk_and_mask<TopkFunc>(
129-
group_scores, num_groups, group_topk, topk_indices, topk_scores, lane_id);
129+
topk_and_mask<TopkFunc>(group_scores, num_groups, group_topk, topk_indices, topk_scores,
130+
lane_id);
130131
__syncwarp();
131132
for (int i = 0; i < group_topk; i++) {
132133
int st = topk_indices[i] * group_size;
@@ -430,7 +431,8 @@ __global__ void fused_topk_with_score_function_forward_kernel(
430431
// Sigmoid/Sqrtsoftplus post-processing when topk > 1
431432
if constexpr (ScoreFunc == 0 || ScoreFunc == 2) {
432433
if (topk > 1) {
433-
CompType sum_scores = warp_reduce_on_shmem<CompType, ReduceFuncType::SUM>(topk_scores, topk, lane_id);
434+
CompType sum_scores =
435+
warp_reduce_on_shmem<CompType, ReduceFuncType::SUM>(topk_scores, topk, lane_id);
434436
for (int i = lane_id; i < topk; i += kThreadsPerWarp) {
435437
topk_scores[i] = topk_scores[i] / (sum_scores + epsilon);
436438
}
@@ -462,8 +464,7 @@ void fused_topk_with_score_function_forward_kernel_launcher(
462464
"num_tokens * num_experts exceeds INT_MAX (kernel uses int offsets), got ",
463465
static_cast<int64_t>(num_tokens) * num_experts);
464466
if (group_topk > 0) {
465-
NVTE_CHECK(topk % group_topk == 0,
466-
"topk must be divisible by group_topk, got topk=", topk,
467+
NVTE_CHECK(topk % group_topk == 0, "topk must be divisible by group_topk, got topk=", topk,
467468
" group_topk=", group_topk);
468469
}
469470
size_t num_token_per_block = kThreadsPerBlock / kThreadsPerWarp;
@@ -504,8 +505,8 @@ void fused_topk_with_score_function_forward_kernel_launcher(
504505
check_shared_memory_capacity_num_experts(other_shmem, num_experts);
505506

506507
auto launch_simple = [&](auto kernel) {
507-
NVTE_CHECK_CUDA(cudaFuncSetAttribute(kernel, cudaFuncAttributeMaxDynamicSharedMemorySize,
508-
other_shmem));
508+
NVTE_CHECK_CUDA(
509+
cudaFuncSetAttribute(kernel, cudaFuncAttributeMaxDynamicSharedMemorySize, other_shmem));
509510
kernel<<<total_blocks, kThreadsPerBlock, other_shmem, stream>>>(
510511
logits, num_tokens, num_experts, topk, use_pre_softmax, num_groups, group_topk,
511512
scaling_factor, score_function, expert_bias, probs, routing_map, intermediate_output);

0 commit comments

Comments
 (0)