Skip to content

Commit

Permalink
Merge pull request PaddlePaddle#46 from mthreads/cpp_lint
Browse files Browse the repository at this point in the history
[MTAI-484] fix(build): modify code format for cpplint
  • Loading branch information
caizhi-mt authored and mt-robot committed Aug 15, 2023
2 parents 4924282 + e17119f commit eb7311f
Show file tree
Hide file tree
Showing 215 changed files with 908 additions and 530 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ repos:
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx)$
args:
- --extensions=c,cc,cxx,cpp,cu,cuh,h,hpp,hxx,kps
- --filter=-readability/fn_size,-build/include_what_you_use,-build/c++11,-whitespace/parens,-whitespace/braces
- --filter=-readability/fn_size,-build/include_what_you_use,-build/c++11,-whitespace/parens,-whitespace/braces,-build/include
- --quiet
# Exclude third-party libraries
exclude: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ void ScaleAPI(const paddle::Tensor& x,
bias_after_scale,
dense_out.get());

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
} else if (expected_kernel_place == paddle::platform::CUDAPlace()) {
auto* dev_ctx =
dynamic_cast<phi::GPUContext*>(pool.Get(expected_kernel_place));
Expand Down
6 changes: 4 additions & 2 deletions paddle/fluid/framework/details/gather_op_handle_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ struct TestGatherOpHandle {

void InitCtxOnGpu(bool use_gpu) {
if (use_gpu) {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
int count = p::GetGPUDeviceCount();
if (count <= 1) {
LOG(WARNING) << "Cannot test multi-gpu Broadcast, because the CUDA "
Expand Down Expand Up @@ -224,7 +225,8 @@ TEST(GatherTester, TestCPUGatherTestSelectedRows) {
test_op.TestGatherSelectedRows(input_scope_idx);
}

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)

TEST(GatherTester, TestGPUGatherTestSelectedRows) {
TestGatherOpHandle test_op;
Expand Down
6 changes: 4 additions & 2 deletions paddle/fluid/framework/dlpack_tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ struct DLDeviceVisitor {
}

inline ::DLDevice operator()(const platform::CUDAPlace &place) const {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
::DLDevice device;
device.device_type = kDLGPU;
device.device_id = place.device;
Expand All @@ -108,7 +109,8 @@ struct DLDeviceVisitor {
}

inline ::DLDevice operator()(const platform::CUDAPinnedPlace &place) const {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
::DLDevice device;
device.device_type = kDLCPUPinned;
device.device_id = 0;
Expand Down
3 changes: 2 additions & 1 deletion paddle/fluid/framework/ir/fuse_bn_add_act_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace framework {
namespace ir {

void FuseBatchNormAddActPass::ApplyImpl(ir::Graph *graph) const {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_HIP) || CUDNN_VERSION_MIN(7, 4, 1)
// forward
std::unordered_set<std::string> act_types = {"relu"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ TEST(test_reference_count_pass, test_no_need_buffer_var_shrink) {
{});

std::vector<bool> use_cuda_list{false};
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
use_cuda_list.push_back(true);
#endif
for (auto use_cuda : use_cuda_list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ inline std::tuple<int, int> GetThreadPoolConfig(const phi::Place& place,
processor_count = std::thread::hardware_concurrency();
if (processor_count) {
if (platform::is_gpu_place(place)) {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
device_count = phi::backends::gpu::GetGPUDeviceCount();
#endif
}
Expand Down
3 changes: 2 additions & 1 deletion paddle/fluid/framework/op_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ struct OpKernelRegistrarFunctorEx<PlaceType,
::paddle::framework::OpKernelType::kDefaultCustomizedTypeValue, \
__VA_ARGS__)

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
#define REGISTER_OP_CUDA_KERNEL(op_type, ...) \
REGISTER_OP_KERNEL(op_type, CUDA, ::paddle::platform::CUDAPlace, __VA_ARGS__)
#else
Expand Down
3 changes: 2 additions & 1 deletion paddle/fluid/framework/phi_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ phi::KernelKey FallBackToCpu(const phi::KernelKey& kernel_key,
phi::Backend::CPU, kernel_key.layout(), kernel_key.dtype());
}
#endif
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
if (kernel_key.backend() == phi::Backend::GPU ||
kernel_key.backend() == phi::Backend::GPUDNN) {
PADDLE_THROW(
Expand Down
3 changes: 2 additions & 1 deletion paddle/fluid/framework/phi_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ struct ConvertToPhiContext<phi::CPUContext> {
using TYPE = phi::CPUContext;
};

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
template <>
struct ConvertToPhiContext<phi::GPUContext> {
using TYPE = phi::GPUContext;
Expand Down
25 changes: 16 additions & 9 deletions paddle/fluid/framework/tensor_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ void TensorCopyImpl(const TENSOR& src,
"Copy from %s to %s is not supported.", src_place, dst_place));
}
#endif
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
else if (platform::is_cuda_pinned_place(src_place) && // NOLINT
platform::is_cuda_pinned_place(dst_place)) {
memory::Copy(dst_place, dst_ptr, src_place, src_ptr, size);
Expand Down Expand Up @@ -377,7 +378,8 @@ void TensorCopySync(const phi::DenseTensor& src,
"Copy from %s to %s is not supported.", src_place, dst_place));
}
#endif
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
else if (platform::is_cuda_pinned_place(src_place) && // NOLINT
platform::is_cuda_pinned_place(dst_place)) {
memory::Copy(dst_place, dst_ptr, src_place, src_ptr, size);
Expand Down Expand Up @@ -479,7 +481,8 @@ void TensorToStream(std::ostream& os,
platform::errors::ResourceExhausted(
"tensor size %d overflow when writing tensor", size));
if (platform::is_gpu_place(tensor.place())) {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
constexpr size_t kBufSize = 1024 * 1024 * 64; // 64MB
std::unique_ptr<char[]> buf(new char[kBufSize]);
auto& gpu_dev_ctx = static_cast<const phi::GPUContext&>(dev_ctx);
Expand Down Expand Up @@ -613,8 +616,9 @@ void TensorFromStream(std::istream& is,
if (platform::is_gpu_place(dev_ctx.GetPlace()) ||
platform::is_xpu_place(dev_ctx.GetPlace()) ||
platform::is_custom_place(dev_ctx.GetPlace())) {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA) || \
defined(PADDLE_WITH_XPU) || defined(PADDLE_WITH_CUSTOM_DEVICE)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA) || defined(PADDLE_WITH_XPU) || \
defined(PADDLE_WITH_CUSTOM_DEVICE)
phi::DenseTensor cpu_tensor;
cpu_tensor.Resize(phi::make_ddim(shape));
framework::VisitDataType(
Expand Down Expand Up @@ -686,8 +690,9 @@ void TensorFromStream(std::istream& is,
if (platform::is_gpu_place(dev_ctx.GetPlace()) ||
platform::is_xpu_place(dev_ctx.GetPlace()) ||
platform::is_custom_place(dev_ctx.GetPlace())) {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA) || \
defined(PADDLE_WITH_XPU) || defined(PADDLE_WITH_CUSTOM_DEVICE)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA) || defined(PADDLE_WITH_XPU) || \
defined(PADDLE_WITH_CUSTOM_DEVICE)
phi::DenseTensor cpu_tensor;
cpu_tensor.Resize(phi::make_ddim(dims));
framework::VisitDataType(
Expand Down Expand Up @@ -809,7 +814,8 @@ void TensorFromDLPack(const ::DLTensor& dl_tensor, phi::DenseTensor* dst) {
if (dl_tensor.device.device_type == kDLCPU) {
memory::Copy(dst_place, dst_ptr, src_place, src_ptr, size);
}
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
if (dl_tensor.device.device_type == kDLGPU) {
platform::CUDAPlace dst_place =
platform::CUDAPlace(dl_tensor.device.device_id);
Expand Down Expand Up @@ -849,7 +855,8 @@ void TensorFromDLPack(const DLManagedTensor* src, phi::DenseTensor* dst) {
void* dst_ptr = GetDstPtrByDLDataType(type, dst, dst_place);
memory::Copy(dst_place, dst_ptr, src_place, src_ptr, size);
}
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
if (src->dl_tensor.device.device_type == kDLGPU) {
platform::CUDAPlace dst_place =
platform::CUDAPlace(src->dl_tensor.device.device_id);
Expand Down
12 changes: 8 additions & 4 deletions paddle/fluid/framework/tensor_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ void TensorFromArray(const T* src,
if (platform::is_cpu_place(dst_place)) {
memory::Copy(dst_place, dst_ptr, src_place, src_ptr, size);
}
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
else if (platform::is_gpu_place(dst_place)) { // NOLINT
memory::Copy(dst_place,
dst_ptr,
Expand Down Expand Up @@ -175,7 +176,8 @@ void TensorFromVector(const std::vector<T>& src,
if (platform::is_cpu_place(dst_place)) {
memory::Copy(dst_place, dst_ptr, src_place, src_ptr, size);
}
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
else if (platform::is_gpu_place(dst_place)) { // NOLINT
memory::Copy(dst_place,
dst_ptr,
Expand Down Expand Up @@ -304,7 +306,8 @@ void TensorToVector(const phi::DenseTensor& src,
if (platform::is_cpu_place(src.place())) {
memory::Copy(dst_place, dst_ptr, src.place(), src_ptr, size);
}
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
else if (platform::is_gpu_place(src.place())) { // NOLINT
memory::Copy(dst_place,
dst_ptr,
Expand Down Expand Up @@ -346,7 +349,8 @@ inline void TensorToVector(const phi::DenseTensor& src,
if (platform::is_cpu_place(src.place())) {
memory::Copy(dst_place, dst_ptr, src.place(), src_ptr, size);
}
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
else if (platform::is_gpu_place(src.place())) { // NOLINT
memory::Copy(dst_place,
dst_ptr,
Expand Down
9 changes: 6 additions & 3 deletions paddle/fluid/framework/trainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ class HeterServiceContext {
int place_num_;
Scope* scope_{nullptr};

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
gpuEvent_t event_;
#endif
std::vector<OperatorBase*> ops_;
Expand Down Expand Up @@ -204,7 +205,8 @@ class HeterXpuTrainer : public TrainerBase {
virtual std::string GetDumpPath(int tid) { return ""; }
virtual void InitDumpEnv() {}
template <typename T>
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
void HeterMemCpy(phi::DenseTensor* tensor,
phi::DenseTensor* root_tensor,
const paddle::platform::Place& thread_place,
Expand Down Expand Up @@ -242,7 +244,8 @@ class HeterXpuTrainer : public TrainerBase {
std::vector<Scope*> place_scopes_;
BtObjectPool<HeterServiceContext> object_pool_;
std::vector<platform::Place> places_;
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
std::vector<gpuStream_t> copy_streams_;
std::vector<gpuEvent_t> events_;
#endif
Expand Down
15 changes: 10 additions & 5 deletions paddle/fluid/inference/api/analysis_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
#include "paddle/fluid/inference/tensorrt/helper.h"
#endif

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
PHI_DECLARE_uint64(initial_gpu_memory_in_mb);
#endif

Expand Down Expand Up @@ -100,7 +101,8 @@ void AnalysisConfig::SetModel(const std::string &prog_file_path,
void AnalysisConfig::EnableUseGpu(uint64_t memory_pool_init_size_mb,
int device_id,
Precision precision_mode) {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
use_gpu_ = true;
memory_pool_init_size_mb_ = memory_pool_init_size_mb;
FLAGS_initial_gpu_memory_in_mb = memory_pool_init_size_mb_;
Expand Down Expand Up @@ -630,7 +632,8 @@ AnalysisConfig::AnalysisConfig(const AnalysisConfig &other) {
}

void AnalysisConfig::EnableCUDNN() {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
use_cudnn_ = use_gpu_;
#else
LOG(ERROR) << "Please compile with CUDA first to use cuDNN";
Expand Down Expand Up @@ -928,7 +931,8 @@ void AnalysisConfig::Update() {
}

if (use_gpu() && use_cudnn_) {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
if (!enable_ir_optim_) {
LOG(ERROR) << "EnableCUDNN() only works when IR optimization is enabled.";
} else {
Expand Down Expand Up @@ -1145,7 +1149,8 @@ void AnalysisConfig::SetCpuMathLibraryNumThreads(
}

float AnalysisConfig::fraction_of_gpu_memory_for_pool() const {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
// Get the GPU memory details and calculate the fraction of memory for the
// GPU memory pool.
size_t gpu_total, gpu_available;
Expand Down
3 changes: 2 additions & 1 deletion paddle/fluid/inference/api/api_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ bool NativePaddlePredictor::SetFeed(const std::vector<PaddleTensor> &inputs,
false,
platform::errors::InvalidArgument(
"Only one choice can be made between CPU and XPU."));
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
platform::DeviceContextPool &pool =
platform::DeviceContextPool::Instance();
auto *dev_ctx = static_cast<const phi::GPUContext *>(pool.Get(place_));
Expand Down
3 changes: 2 additions & 1 deletion paddle/fluid/inference/api/infer_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class InferCPUContext : public phi::CPUContext {
using phi::CPUContext::SetEigenDevice;
};

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
class InferGPUContext : public phi::GPUContext {
public:
explicit InferGPUContext(const phi::Place& place);
Expand Down
9 changes: 6 additions & 3 deletions paddle/fluid/inference/api/resource_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
namespace paddle {
namespace internal {

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
class EigenGpuStreamDevice : public Eigen::StreamInterface {
public:
EigenGpuStreamDevice() : scratch_(nullptr), semaphore_(nullptr) {
Expand Down Expand Up @@ -135,7 +136,8 @@ void CPUContextResource::InitCPUResource() {

CPUContextResource::CPUContextResource() { InitCPUResource(); }

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
GPUContextResource::GPUContextResource(const phi::Place& place, void* stream)
: place_(place) {
InitGPUResource(stream);
Expand Down Expand Up @@ -385,7 +387,8 @@ CPUContextResource* ResourceManager::GetCPUResource() const {
return cpu_resource_.get();
}

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
void* ResourceManager::InitGPUResource(const phi::Place& place, void* stream) {
std::lock_guard<std::mutex> lock_gurad(gpu_mutex_);
if (gpu_resources_.count(stream)) {
Expand Down
9 changes: 6 additions & 3 deletions paddle/fluid/inference/api/resource_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#include "paddle/phi/common/place.h"
#include "unsupported/Eigen/CXX11/Tensor"

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
#include "paddle/fluid/platform/device/gpu/gpu_types.h"
#include "paddle/phi/backends/gpu/forwards.h"
#include "paddle/phi/backends/gpu/gpu_decls.h"
Expand All @@ -49,7 +50,8 @@ class CPUContextResource {
std::unique_ptr<Eigen::DefaultDevice> cpu_eigen_device_;
};

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
class GPUContextResource {
public:
explicit GPUContextResource(const phi::Place& place, void* stream);
Expand Down Expand Up @@ -149,7 +151,8 @@ class ResourceManager {
std::mutex cpu_mutex_;
std::unique_ptr<CPUContextResource> cpu_resource_{nullptr};

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || defined(PADDLE_WITH_MUSA)
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_MUSA)
// GPU Resource
public:
void* InitGPUResource(const phi::Place& place, void* stream);
Expand Down
Loading

0 comments on commit eb7311f

Please sign in to comment.