Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PTEN] Add pten::Place data structure. #38844

Merged
merged 4 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions paddle/pten/api/lib/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cc_library(pten_api_utils SRCS allocator.cc storage.cc tensor_utils.cc place_utils.cc DEPS
tensor_base convert_utils dense_tensor lod_tensor selected_rows place var_type_traits pten_common)
cc_library(pten_api_utils SRCS allocator.cc storage.cc tensor_utils.cc DEPS
tensor_base convert_utils dense_tensor lod_tensor selected_rows place var_type_traits)
62 changes: 0 additions & 62 deletions paddle/pten/api/lib/utils/place_utils.cc

This file was deleted.

28 changes: 0 additions & 28 deletions paddle/pten/api/lib/utils/place_utils.h

This file was deleted.

2 changes: 1 addition & 1 deletion paddle/pten/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cc_library(pten_common SRCS device.cc place.cc DEPS enforce)
cc_library(pten_place SRCS place.cc)
65 changes: 0 additions & 65 deletions paddle/pten/common/device.cc

This file was deleted.

70 changes: 0 additions & 70 deletions paddle/pten/common/device.h

This file was deleted.

57 changes: 50 additions & 7 deletions paddle/pten/common/place.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -13,14 +13,57 @@ See the License for the specific language governing permissions and
limitations under the License. */

#include "paddle/pten/common/place.h"
#include "paddle/fluid/platform/enforce.h"

namespace paddle {
namespace experimental {
#include <sstream>
#include <string>

#include "paddle/pten/api/ext/exception.h"

namespace pten {

const char *AllocationTypeStr(AllocationType type) {
switch (type) {
case AllocationType::UNDEF:
return "undef";
case AllocationType::CPU:
return "cpu";
case AllocationType::GPU:
return "gpu";
case AllocationType::GPUPINNED:
return "gpu pinned";
case AllocationType::XPU:
return "xpu";
case AllocationType::NPU:
return "npu";
case AllocationType::NPUPINNED:
return "npu pinned";
case AllocationType::IPU:
return "ipu";
case AllocationType::MLU:
return "mlu";
default:
PD_THROW("Invalid pten device type.");
return {};
}
}

std::string Place::DebugString() const {
return device_.DebugString() + ", is_pinned: " + std::to_string(is_pinned_);
std::ostringstream os;
os << "Place(";
os << AllocationTypeStr(alloc_type_);
if (alloc_type_ == AllocationType::GPUPINNED ||
alloc_type_ == AllocationType::NPUPINNED ||
alloc_type_ == AllocationType::CPU) {
os << ")";
} else {
os << ":" << std::to_string(device) << ")";
}
return os.str();
}

std::ostream &operator<<(std::ostream &os, const Place &p) {
os << p.DebugString();
return os;
}

} // namespace experimental
} // namespace paddle
} // namespace pten
Loading