Skip to content

Conversation

@HydrogenSulfate
Copy link
Contributor

@HydrogenSulfate HydrogenSulfate commented Oct 29, 2025

PR Category

Operator Mechanism

PR Types

New features

Description

Pcard-75624

支持 cuda、xpu 设备的paddle.uniform复数类型,对实部和虚部分别 uniform 后拼接成复数

大Tensor显存测试代码:

import paddle

with paddle.no_grad():
    for i in range(10):
        x = paddle.uniform([(1<<31)+100], dtype=paddle.complex64)
        print(x.mean().item())
        print(paddle.cuda.max_memory_allocated())

with paddle.no_grad():
    for i in range(10):
        x = paddle.uniform([(1<<31)+100], dtype=paddle.complex64, seed=42)
        print(x.mean().item())
        print(paddle.cuda.max_memory_allocated())

"""
W1104 18:51:08.285594 37178 gpu_resources.cc:114] Please NOTE: device: 0, GPU Compute Capability: 8.0, Driver API Version: 12.6, Runtime API Version: 12.6
(-1.850718035711907e-05+1.849587533797603e-05j)
17180394752
(-1.8500228179618716e-05+1.8497743440093473e-05j)
34359740416
(-1.850174339779187e-05+1.8496502889320254e-05j)
34359740416
(-1.8498300050850958e-05+1.849878935900051e-05j)
34359740416
(-1.8507726053940132e-05+1.8492213712306693e-05j)
34359740416
(-1.85028875421267e-05+1.850071748776827e-05j)
34359740416
(-1.850380613177549e-05+1.8496262782718986e-05j)
34359740416
(-1.8501710655982606e-05+1.8499011275707744e-05j)
34359740416
(-1.8502383682061918e-05+1.849904583650641e-05j)
34359740416
(-1.8502505554351956e-05+1.84961663762806e-05j)
34359740416
(-1.8501950762583874e-05+1.850116314017214e-05j)
34359740416
(-1.8502525563235395e-05+1.8496037228032947e-05j)
34359740416
(-1.850007174653001e-05+1.8500673832022585e-05j)
34359740416
(-1.8502983948565088e-05+1.850039370765444e-05j)
34359740416
(-1.8501823433325626e-05+1.8499888028600253e-05j)
34359740416
(-1.8504824765841477e-05+1.8494234609534033e-05j)
34359740416
(-1.850007538450882e-05+1.8497394194127992e-05j)
34359740416
(-1.8502336388337426e-05+1.8500135411159135e-05j)
34359740416
(-1.8506556443753652e-05+1.850123589974828e-05j)
34359740416
(-1.850054286478553e-05+1.8497887140256353e-05j)
34359740416
"""

This pull request adds support for generating random numbers from a uniform distribution for complex data types (complex64 and complex128) in Paddle's GPU kernel and Python API. The changes include updates to both backend CUDA kernel logic and the Python interface, as well as additional tests to ensure correct behavior.

Complex uniform random support:

  • The GPU kernel (uniform_kernel.cu) now handles complex64 and complex128 types by generating real and imaginary parts separately and combining them. This includes logic for both global and operator-specific seeds.
  • The kernel registration macro is updated to include phi::complex64 and phi::complex128, enabling dispatch for these types.

Python API and documentation:

  • The Python uniform function now documents and accepts complex64 and complex128 as supported dtypes. [1] [2]

Testing:

  • Two new test classes are added to explicitly test uniform random generation for np.complex64 and np.complex128 in test_uniform_random_op.py.

Other:

  • Additional includes are added in uniform_kernel.cu to support complex types and type traits.
  • Minor formatting and function boundary changes to accommodate new logic.

@paddle-bot
Copy link

paddle-bot bot commented Oct 29, 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.

@codecov-commenter
Copy link

codecov-commenter commented Oct 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@a9319a2). Learn more about missing BASE report.

Additional details and impacted files
@@             Coverage Diff             @@
##             develop    #76117   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?         2           
  Lines              ?        17           
  Branches           ?         0           
===========================================
  Hits               ?        17           
  Misses             ?         0           
  Partials           ?         0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@wanghuancoder wanghuancoder left a comment

Choose a reason for hiding this comment

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

LGTM

@HydrogenSulfate HydrogenSulfate merged commit 23d449e into PaddlePaddle:develop Nov 4, 2025
140 of 154 checks passed
@HydrogenSulfate HydrogenSulfate deleted the add_complex_kernel branch November 4, 2025 11:09
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.

3 participants