Skip to content

Conversation

@zrr1999
Copy link
Member

@zrr1999 zrr1999 commented Nov 7, 2025

PR Category

Operator Mechanism

PR Types

Bug fixes

Description

将通过四则运算计算得到的且原本类型为int的变量统一使用auto,可以大幅度减少后续将其他变量修改为int64时的工作量。

应用下列rule

id: const-int-arith-combo
language: cpp
files:
  - paddle/phi/kernels/**
ignores:
  - paddle/phi/kernels/legacy/**
  - paddle/phi/kernels/xpu/**
  - paddle/phi/kernels/custom/**
  - paddle/phi/kernels/sparse/**
severity: warning
message: const int/int32_t initialized from a (possibly complex) arithmetic expression
rule:
  any:
    # 赋值初始化:const T var = <complex arithmetic expr>;
    - pattern: const $T $VAR = $EXPR
    # 直接初始化:const T var(<complex arithmetic expr>);
    - pattern: const $T $VAR($EXPR)
constraints:
  T:
    regex: ^(int|int32_t)$
  EXPR:
    all:
      - any:
        - has:
            pattern: $A + $B
        - has:
            pattern: $A - $B
        - has:
            pattern: $A * $B
        - has:
            pattern: $A / $B
      - not:
          regex: \b(threadIdx|blockDim|blockIdx)\b
fix: |
  const auto $VAR($EXPR);


id: nonconst-int-arith-combo
language: cpp
files:
  - paddle/phi/kernels/**
ignores:
  - paddle/phi/kernels/legacy/**
  - paddle/phi/kernels/xpu/**
  - paddle/phi/kernels/custom/**
  - paddle/phi/kernels/sparse/**
severity: warning
message: int/int32_t initialized from a (possibly complex) arithmetic expression
rule:
  any:
    # 赋值初始化:T var = <complex arithmetic expr>;
    - pattern: $T $VAR = $EXPR
    # 直接初始化:T var(<complex arithmetic expr>);
    - pattern: $T $VAR($EXPR)
constraints:
  T:
    regex: ^(int|int32_t)$
  EXPR:
    all:
      - any:
        - has:
            pattern: $A + $B
        - has:
            pattern: $A - $B
        - has:
            pattern: $A * $B
        - has:
            pattern: $A / $B
      - not:
          regex: \b(threadIdx|blockDim|blockIdx)\b
fix: |
  auto $VAR = $EXPR;

pcard-93269

@paddle-bot
Copy link

paddle-bot bot commented Nov 7, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@zrr1999 zrr1999 force-pushed the big-tensor/int-arith-combo branch from 922e0e8 to 830021b Compare November 7, 2025 09:00
@zrr1999 zrr1999 requested a review from Copilot November 7, 2025 09:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request systematically converts explicit integer type declarations (primarily int, int32_t, int64_t) to use auto type deduction across a large number of files in the PaddlePaddle codebase. The changes affect kernel implementations, utility functions, and CUTLASS extensions.

Key Changes:

  • Mass conversion of explicit integer types to auto for variables initialized with arithmetic expressions
  • Introduction of direct initialization syntax with parentheses (e.g., const auto var(expr)) instead of copy initialization
  • Changes span GPU kernels, CPU kernels, fusion kernels, and utility functions

Reviewed Changes

Copilot reviewed 180 out of 180 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
paddle/phi/kernels/strings/gpu/copy_utils.h Changed int64_t numel to auto numel - potential overflow risk
paddle/phi/kernels/stride/reduce_grad_stride_kernel.cu Changed int tmp_dim to auto tmp_dim
paddle/phi/kernels/primitive/datamover_primitives_xpu2.h Multiple int to auto conversions for buffer calculations
paddle/phi/kernels/primitive/compute_primitives.h Index calculations changed from int to auto
paddle/phi/kernels/onednn/*.cc Multiple conversions with direct initialization syntax
paddle/phi/kernels/impl/*.h Extensive int to auto conversions in implementation headers
paddle/phi/kernels/gpu/*.cu GPU kernel index calculations converted to auto
paddle/phi/kernels/fusion/gpu/*.cu Fusion kernel optimizations with auto type deduction
paddle/phi/kernels/funcs/*.{cu,cc,h} Utility function conversions to auto

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant