From 35839aee246c07b52fc73f49f3a055e27c95f0b8 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Wed, 10 Aug 2022 04:03:50 -0500 Subject: [PATCH] polish backend and layout details (#45029) --- paddle/phi/common/backend.h | 3 +-- paddle/phi/common/layout.h | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/paddle/phi/common/backend.h b/paddle/phi/common/backend.h index c6d49bd5b97..bfdc3814823 100644 --- a/paddle/phi/common/backend.h +++ b/paddle/phi/common/backend.h @@ -48,6 +48,7 @@ enum class Backend : uint8_t { XPU, // XPU currently does not exist at the same time as CUDA NPU, // NPU currently does not exist at the same time as CUDA MLU, // MLU currently does not exist at the same time as CUDA + IPU, // the third library backend ONEDNN, @@ -56,8 +57,6 @@ enum class Backend : uint8_t { // paddle kernel primitives backend KPS, - IPU, - // end of backend types NUM_BACKENDS, diff --git a/paddle/phi/common/layout.h b/paddle/phi/common/layout.h index 6b2f657699f..2d74abeb84d 100644 --- a/paddle/phi/common/layout.h +++ b/paddle/phi/common/layout.h @@ -18,8 +18,20 @@ limitations under the License. */ namespace paddle { namespace experimental { +// Note: The original design of paddle DataLayout is confusing. +// It contains two levels of "layout", one is the data layout +// at the Tensor level, including Dense, Sparse, etc., and the other +// is the format at the data level, including NHWC, NCHW, etc., +// these should belong to the concept of "data format". +// The concepts of these two levels are mixed into an enumeration class, +// which leads to some strange execution scheduling logic. +// It needs to be refactored in the future. +// In order to maintain compatibility, we still use the design of the +// original framework here. + // Note: Here the DataLayout is public api for external users, the prefix `k` // maybe confuse users, so we use all uppercase names + enum class DataLayout { UNDEFINED = 0, // TODO(chenweihang): keep ANY for compatibility, remove it later @@ -32,16 +44,21 @@ enum class DataLayout { SPARSE_COO, SPARSE_CSR, PSTRING_UNION, + NUM_DATA_LAYOUTS, + // See Note [ Why we need ALL in basic kernel key member? ] ALL_LAYOUT = UNDEFINED, + // Note: Unify phi DataLayout and fluid::framework::DataLayout, // for compatible with fluid DataLayout, here need prefix `k` + // Note: The original `kAnyLayout (enum value 2)` is a strange design. // `kAnyLayout` originally cannot represent any kind of Layout, // at the same time, it can also represent any Layout. // Strictly, it means "default" or "undefined" layout, - // and should not be mixed with other meaningful layouts. + // and should not be mixed with other meaningful layouts + kAnyLayout = ANY, kNHWC = NHWC, kNCHW = NCHW, -- GitLab