Skip to content

Commit

Permalink
[PTEN] Add pten::Place data structure. (#38844)
Browse files Browse the repository at this point in the history
* add pten::Place data structure.

* update ci problem

* fix ci problem

* update
  • Loading branch information
jiweibo authored Jan 11, 2022
1 parent 29c211e commit 2bed9b9
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 345 deletions.
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

0 comments on commit 2bed9b9

Please sign in to comment.