Skip to content

[Bug Fix] Fix CastDataTypeFunctor for low-precision floats to complex types#75934

Merged
luotao1 merged 5 commits intoPaddlePaddle:developfrom
youge325:fluid
Oct 24, 2025
Merged

[Bug Fix] Fix CastDataTypeFunctor for low-precision floats to complex types#75934
luotao1 merged 5 commits intoPaddlePaddle:developfrom
youge325:fluid

Conversation

@youge325
Copy link
Copy Markdown
Contributor

PR Category

Environment Adaptation

PR Types

Bug fixes

Description

  • 新增了 CastDataTypeFunctor 针对 float8_e5m2float8_e4m3fnfloat16bfloat16complex<float>/complex<double> 的专门实现。
  • 原本的泛型实现只做 static_cast<OutType>(in),而 phi::dtype::complex<> 没有接受这些低精度实数类型的隐式转换,实际调用 TransDataType 做类型转换时会缺失对应路径或触发编译/运行错误。
  • 现在在转换时先显式转成 float/double 再构造复数,就能让这些低精度实数张量安全地转换成复数张量,确保在需要复数输出(例如调用复数 kernel)时类型升级可以顺利执行。
  • 编译时的错误日志:
[88/1477] Building CUDA object paddle\fluid\framework\CMakeFiles\data_type_transform.dir\.data_type_transform.cu.obj
FAILED: paddle/fluid/framework/CMakeFiles/data_type_transform.dir/.data_type_transform.cu.obj
C:\PROGRA~1\NVIDIA~2\CUDA\v13.0\bin\nvcc.exe -forward-unknown-to-host-compiler -DCUDA_TOOLKIT_ROOT_DIR="\"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0\"" -DCUDA_VERSION_MAJOR=\"13\" -DCUDA_VERSION_MINOR=\"0\" -DCUDNN_MAJOR_VERSION=\"9\" -DEIGEN_STRONG_INLINE=inline -DEIGEN_USE_GPU -DGLOG_NO_ABBREVIATED_SEVERITIES -DGOOGLE_GLOG_DLL_DECL="" -DLAPACK_FOUND -DNOMINMAX -DPADDLE_DISABLE_PROFILER -DPADDLE_DLL_EXPORT -DPADDLE_DLL_INFERENCE -DPADDLE_ON_INFERENCE -DPADDLE_VERSION=0.0.0 -DPADDLE_VERSION_INTEGER=0 -DPADDLE_WITH_AVX -DPADDLE_WITH_CCCL -DPADDLE_WITH_CRYPTO -DPADDLE_WITH_CUDA -DPADDLE_WITH_DNNL -DPADDLE_WITH_MKLML -DPADDLE_WITH_PIP_CUDA_LIBRARIES -DPADDLE_WITH_POCKETFFT -DPADDLE_WITH_SSE3 -DPADDLE_WITH_TENSORRT -DPHI_INNER -DPHI_SHARED -DSTATIC_IR -DTRT_PLUGIN_FP16_AVAILABLE -DUTF8PROC_STATIC -DWIN32_LEAN_AND_MEAN -DYAML_CPP_STATIC_DEFINE -D_XKEYCHECK_H -ID:\Paddle\third_party\cccl\thrust -ID:\Paddle\third_party\cccl\libcudacxx\include -ID:\Paddle\third_party\cccl\cub -ID:\Paddle\build -ID:\Paddle\paddle\fluid\framework\io -ID:\Paddle\patches\thrust -ID:\TensorRT-10.13.3.9\include -ID:\Paddle\build\third_party\install\zlib\include -ID:\Paddle\build\third_party\install -ID:\Paddle\build\third_party\install\gflags\include -ID:\Paddle\build\third_party\install\glog\include -ID:\Paddle\third_party\eigen3 -ID:\Paddle\third_party\threadpool -ID:\Paddle\third_party\dlpack\include -ID:\Paddle\build\third_party\install\xxhash\include -ID:\Paddle\build\third_party\install\warpctc\include -ID:\Paddle\build\third_party\install\warprnnt\include -ID:\Paddle\build\third_party\install\utf8proc\include -ID:\Paddle\build\third_party\install\mklml\include -ID:\Paddle\build\third_party\install\onednn\include -ID:\Paddle\build\third_party\install\protobuf\include -ID:\Paddle\third_party\nlohmann_json\include -ID:\Paddle\build\third_party\install\yaml-cpp\include -ID:\Users\Lenovo\AppData\Local\Programs\Python\Python310\include -ID:\Users\Lenovo\AppData\Local\Programs\Python\Python310\Lib\site-packages\numpy\core\include -ID:\Paddle\build\third_party\pybind\src\extern_pybind\include -ID:\Paddle\build\third_party\install\libuv\include -ID:\Paddle\third_party\cccl -ID:\Paddle\build\third_party\install\cryptopp\include -ID:\Paddle\build\third_party\pocketfft\src -ID:\Paddle\build\third_party\dirent\src\extern_dirent\include -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include" -ID:\Paddle -ID:\Paddle\paddle\phi\api\include\compat -ID:\Paddle\paddle\phi\api\include\compat\torch\csrc\api\include -ID:\Paddle\build\..\paddle\fluid\framework\io -D_WINDOWS -Xcompiler=" /W0  /GR /EHsc"  -gencode arch=compute_86,code=sm_86 -Xfatbin -compress-all -w --expt-relaxed-constexpr --expt-extended-lambda -Xcompiler "/wd4244 /wd4267 /wd4819 " -Xcompiler /bigobj -std=c++17  -Xcompiler="/arch:AVX" -Xcompiler="-MT -O2 -Ob2" -DNDEBUG -std=c++17 -MD -MT paddle\fluid\framework\CMakeFiles\data_type_transform.dir\.data_type_transform.cu.obj -MF paddle\fluid\framework\CMakeFiles\data_type_transform.dir\.data_type_transform.cu.obj.d -x cu -c D:\Paddle\paddle\fluid\framework\.data_type_transform.cu -o paddle\fluid\framework\CMakeFiles\data_type_transform.dir\.data_type_transform.cu.obj -Xcompiler=-Fdpaddle\fluid\framework\CMakeFiles\data_type_transform.dir\data_type_transform.pdb,-FS
.data_type_transform.cu
tmpxft_0000020c_00000000-7_.data_type_transform.cudafe1.cpp
D:\Paddle\paddle\fluid\framework\.data_type_transform.cu(31): error C2440: 'static_cast': cannot convert from 'InType' to 'OutType'
        with
        [
            InType=phi::dtype::float8_e5m2
        ]
        and
        [
            OutType=phi::dtype::complex<double>
        ]
D:\Paddle\paddle\fluid\framework\.data_type_transform.cu(31): note: 'phi::dtype::complex<double>::complex': no overloaded function could convert all the argument types
D:/Paddle\paddle/phi/common/complex.h(126): note: could be 'phi::dtype::complex<double>::complex<T>(const phi::dtype::complex<float> &)'
        with
        [
            T=double
        ]
D:\Paddle\paddle\fluid\framework\.data_type_transform.cu(31): note: 'phi::dtype::complex<double>::complex<T>(const phi::dtype::complex<float> &)': cannot convert argument 1 from 'InType' to 'const phi::dtype::complex<float> &'
        with
        [
            T=double
        ]
        and
        [
            InType=phi::dtype::float8_e5m2
        ]
D:\Paddle\paddle\fluid\framework\.data_type_transform.cu(31): note: Reason: cannot convert from 'InType' to 'const phi::dtype::complex<float>'
        with
        [
            InType=phi::dtype::float8_e5m2
        ]
D:\Paddle\paddle\fluid\framework\.data_type_transform.cu(31): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
D:/Paddle\paddle/phi/common/complex.h(140): note: or       'phi::dtype::complex<double>::complex(const std::complex<_Other> &)'
D:/Paddle\paddle/phi/common/complex.h(118): note: or       'phi::dtype::complex<double>::complex(const std::enable_if<std::is_same<T1,float>::value,phi::dtype::complex<double>>::type &)'
D:/Paddle\paddle/phi/common/complex.h(113): note: or       'phi::dtype::complex<double>::complex(const T1 &)'
D:/Paddle\paddle/phi/common/complex.h(78): note: or       'phi::dtype::complex<double>::complex(const cuda::std::__4::complex<_Xp> &)'
D:/Paddle\paddle/phi/common/complex.h(71): note: or       'phi::dtype::complex<double>::complex(const thrust::THRUST_200200_860_NS::complex<U> &)'
D:\Paddle\paddle\fluid\framework\.data_type_transform.cu(31): note: while trying to match the argument list '(InType)'
        with
        [
            InType=phi::dtype::float8_e5m2
        ]
D:\Paddle\paddle\fluid\framework\.data_type_transform.cu(31): note: the template instantiation context (the oldest one first) is
C:\Users\Lenovo\AppData\Local\Temp\tmpxft_0000020c_00000000-7_.data_type_transform.cudafe1.stub.c(1318): note: see reference to class template instantiation 'thrust::THRUST_200200_860_NS::cuda_cub::__transform::unary_transform_f<thrust::THRUST_200200_860_NS::device_ptr<const phi::dtype::float8_e5m2>,thrust::THRUST_200200_860_NS::device_ptr<phi::dtype::complex<double>>,thrust::THRUST_200200_860_NS::cuda_cub::__transform::no_stencil_tag,paddle::framework::CastDataTypeFunctor<phi::dtype::float8_e5m2,phi::dtype::complex<double>>,thrust::THRUST_200200_860_NS::cuda_cub::__transform::always_true_predicate>' being compiled
D:/Paddle/third_party/cccl/thrust\thrust/system/cuda/detail/transform.h(104): note: see reference to class template instantiation 'paddle::framework::CastDataTypeFunctor<phi::dtype::float8_e5m2,phi::dtype::complex<double>>' being compiled
D:\Paddle\paddle\fluid\framework\.data_type_transform.cu(30): note: while compiling class template member function 'OutType paddle::framework::CastDataTypeFunctor<phi::dtype::float8_e5m2,OutType>::operator ()(InType) const'
        with
        [
            OutType=phi::dtype::complex<double>,
            InType=phi::dtype::float8_e5m2
        ]
D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\algorithm(3799): note: see the first reference to 'paddle::framework::CastDataTypeFunctor<phi::dtype::float8_e5m2,phi::dtype::complex<double>>::operator ()' in 'std::transform'
D:/Paddle\paddle/phi/common/transform.h(78): note: see the first reference to 'std::transform' in 'phi::Transform<phi::CPUContext>::operator ()'
D:\Paddle\paddle\fluid\framework\.data_type_transform.cu(100): note: see the first reference to 'phi::Transform<phi::CPUContext>::operator ()' in 'paddle::framework::CastDataType<phi::dtype::float8_e5m2>::apply'
D:/Paddle\paddle/fluid/framework/data_type.h(151): note: see the first reference to 'paddle::framework::CastDataType<phi::dtype::float8_e5m2>::apply' in 'paddle::framework::VisitDataType'
[95/1477] Building CXX object paddle\fluid\framework\ir\CM...s\map_op_to_another_pass.dir\map_op_to_another_pass.cc.obj
ninja: build stopped: subcommand failed.

… types

这些改动新增了 `CastDataTypeFunctor` 针对 `float8_e5m2`、`float8_e4m3fn`、`float16` 和 `bfloat16` 到 `complex<float>`/`complex<double>` 的专门实现。原本的泛型实现只做 `static_cast<OutType>(in)`,而 `phi::dtype::complex<>` 没有接受这些低精度实数类型的隐式转换,实际调用 `TransDataType` 做类型转换时会缺失对应路径或触发编译/运行错误。现在在转换时先显式转成 `float`/`double` 再构造复数,就能让这些低精度实数张量安全地转换成复数张量,确保在需要复数输出(例如调用复数 kernel)时类型升级可以顺利执行。
@paddle-bot
Copy link
Copy Markdown

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

@paddle-bot paddle-bot Bot added the contributor External developers label Oct 18, 2025
@youge325
Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label Oct 21, 2025
@youge325
Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@luotao1 luotao1 self-assigned this Oct 22, 2025
@youge325
Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@luotao1 luotao1 merged commit 4887335 into PaddlePaddle:develop Oct 24, 2025
82 of 84 checks passed
@youge325 youge325 deleted the fluid branch October 24, 2025 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers HappyOpenSource 快乐开源活动issue与PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants