Skip to content

[Cpp API Compatibility] Add CUDABlas related APIs#78060

Merged
SigureMo merged 64 commits intoPaddlePaddle:developfrom
youge325:cOthers
Mar 26, 2026
Merged

[Cpp API Compatibility] Add CUDABlas related APIs#78060
SigureMo merged 64 commits intoPaddlePaddle:developfrom
youge325:cOthers

Conversation

@youge325
Copy link
Copy Markdown
Contributor

@youge325 youge325 commented Feb 27, 2026

PR Category

Execute Infrastructure

PR Types

New features

Description

新增 at::cuda::getCurrentCUDABlasHandle at::cuda::blas::gemm<T> 接口

新增 Allocator 结构体

文档详见 PFCCLab/PaddleCppAPITest#46

是否引起精度变化

Copilot AI review requested due to automatic review settings February 27, 2026 09:45
@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented Feb 27, 2026

你的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 Feb 27, 2026
Copy link
Copy Markdown
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 PR extends Paddle’s LibTorch/ATen compatibility layer by introducing a lightweight CUDA context interface and adding missing CUDA/CUBLAS handle accessors needed for C++ API compatibility (notably at::cuda::getCurrentCUDABlasHandle), along with a compat c10::Allocator abstraction.

Changes:

  • Add c10::cuda::device_count() API to the compat CUDA functions header.
  • Introduce compat c10::Allocator (plus DataPtr::release_context() support) for raw allocation APIs.
  • Add ATen/cuda/CUDAContextLight.{h,cpp} and switch ATen/cuda/CUDAContext.h to include the new light header; wire the new .cpp into the compat build.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
paddle/phi/api/include/compat/c10/cuda/CUDAFunctions.h Adds device_count() to the compat c10 CUDA API surface.
paddle/phi/api/include/compat/c10/core/Allocator.h Adds a compat c10::Allocator interface and DataPtr::release_context().
paddle/phi/api/include/compat/CMakeLists.txt Adds the new CUDAContextLight.cpp to the compat compilation sources.
paddle/phi/api/include/compat/ATen/cuda/CUDAContextLight.h Declares lightweight at::cuda CUDA context APIs, including cuBLAS handle getters.
paddle/phi/api/include/compat/ATen/cuda/CUDAContextLight.cpp Implements the lightweight CUDA context APIs via phi::GPUContext.
paddle/phi/api/include/compat/ATen/cuda/CUDAContext.h Redirects CUDAContext to the new lightweight header.

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

Comment thread paddle/phi/api/include/compat/ATen/cuda/CUDAContext.h
Comment thread paddle/phi/api/include/compat/ATen/cuda/CUDAContextLight.h Outdated
Comment thread paddle/phi/api/include/compat/ATen/cuda/CUDAContextLight.h
Comment thread paddle/phi/api/include/compat/ATen/cuda/CUDAContextLight.cpp
Comment thread paddle/phi/api/include/compat/c10/cuda/CUDAFunctions.h Outdated
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 95.18072% with 24 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@362b943). Learn more about missing BASE report.

Files with missing lines Patch % Lines
.../api/include/compat/ATen/cuda/CUDAContextLight.cpp 89.74% 8 Missing ⚠️
paddle/phi/api/include/compat/c10/core/Storage.h 93.79% 8 Missing ⚠️
...ddle/phi/api/include/compat/ATen/core/TensorBase.h 92.72% 4 Missing ⚠️
...addle/phi/api/include/compat/c10/core/DeviceType.h 90.90% 2 Missing ⚠️
...ddle/phi/api/include/compat/ATen/core/TensorBody.h 0.00% 1 Missing ⚠️
paddle/phi/api/include/compat/c10/core/Allocator.h 97.61% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop   #78060   +/-   ##
==========================================
  Coverage           ?   95.18%           
==========================================
  Files              ?       16           
  Lines              ?      498           
  Branches           ?        0           
==========================================
  Hits               ?      474           
  Misses             ?       24           
  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.

@youge325 youge325 force-pushed the cOthers branch 2 times, most recently from c807df9 to 8ebc8c8 Compare February 28, 2026 13:34
@youge325 youge325 changed the title [Cpp API Compatibility] add at::cuda::getCurrentCUDABlasHandle [Cpp API Compatibility] add CUDABlas related APIs Feb 28, 2026
Comment thread paddle/phi/api/include/compat/c10/core/Allocator.h
@youge325 youge325 force-pushed the cOthers branch 17 times, most recently from 7a5c35e to c1cbf14 Compare March 5, 2026 09:51
@youge325 youge325 force-pushed the cOthers branch 2 times, most recently from 1067c2f to adb8b58 Compare March 14, 2026 06:33
@youge325
Copy link
Copy Markdown
Contributor Author

/re-run windows-gpu


#pragma once

#include <cublasXt.h>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

咦,这行改动的原因是?没必要是么?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

这行不去掉的话,在编译的时候 Linux-DCU build会遇到redefinition错误,和 #include <cublas_v2.h> 冲突了,本来是要换一下 include 顺序,但是cpplint会直接换回来,后来发现直接去掉也没问题,这里暂时是用不到 cublasXt.h 的,后面需要用到的时候再 include 也没问题,具体可以看涉及到 fix dcu 的 commit

@SigureMo
Copy link
Copy Markdown
Member

这轮正式结论调整为 APPROVE。

太不容易了啊这个 PR

@youge325
Copy link
Copy Markdown
Contributor Author

/re-run all-failed

1 similar comment
@youge325
Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@SigureMo SigureMo changed the title [Cpp API Compatibility] add CUDABlas related APIs [Cpp API Compatibility] Add CUDABlas related APIs Mar 26, 2026
Copy link
Copy Markdown
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTMeow 🐾

@SigureMo SigureMo merged commit 59e6de0 into PaddlePaddle:develop Mar 26, 2026
125 of 130 checks passed
@youge325 youge325 deleted the cOthers branch March 26, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants