-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[PIR] Refine op yaml system #59364
[PIR] Refine op yaml system #59364
Changes from all commits
eaa4fe1
de17c2b
20635e4
01d0f92
3db66c8
a147ff4
7bbbe5d
fc666b4
746ee5d
6643a8e
dd8bdab
a7c1d2f
8affac5
0c7c4d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) 2023 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. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "paddle/fluid/pir/dialect/operator/ir/ir_selected_rows.h" | ||
|
||
#include "paddle/pir/core/enforce.h" | ||
|
||
namespace paddle { | ||
namespace dialect { | ||
IrSelectedRows::IrSelectedRows(phi::DataType dtype, | ||
const phi::DDim& dims, | ||
phi::DataLayout layout, | ||
const LoD& lod, | ||
size_t offset) | ||
: dims_(dims), dtype_(dtype), layout_(layout), lod_(lod), offset_(offset) {} | ||
|
||
IrSelectedRows::IrSelectedRows(const IrSelectedRows& other) { | ||
dims_ = other.dims(); | ||
dtype_ = other.dtype(); | ||
layout_ = other.layout(); | ||
lod_ = other.lod(); | ||
offset_ = other.offset(); | ||
} | ||
|
||
IrSelectedRows& IrSelectedRows::operator=(const IrSelectedRows& other) { | ||
dims_ = other.dims(); | ||
dtype_ = other.dtype(); | ||
layout_ = other.layout(); | ||
lod_ = other.lod(); | ||
offset_ = other.offset(); | ||
return *this; | ||
} | ||
|
||
IrSelectedRows& IrSelectedRows::operator=(IrSelectedRows&& other) noexcept { | ||
dims_ = std::move(other.dims()); | ||
dtype_ = other.dtype(); | ||
layout_ = other.layout(); | ||
lod_ = std::move(other.lod()); | ||
offset_ = other.offset(); | ||
return *this; | ||
} | ||
|
||
int64_t IrSelectedRows::numel() const { return phi::product(dims_); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里会出现 [128, 3, -1, -1]的场景么?或者说这里的ddim都是非负数了已经 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可能会出现,IrTensor 和 IrSelectRows 仅会PIR组网的 infer meta 阶段使用,全局搜索了一下框架目前所有的 infer_meta 函数,共有2个使用到 numel 的地方:NanmedianInferMeta、FullWithTensorInferMeta,但这两个函数并未对这种情况做处理。目前执行未发现错误应该是因为执行期间还会执行一次 infer_meta. |
||
|
||
const phi::Place& IrSelectedRows::place() const { | ||
IR_THROW("Don't use IrSelectedRows::place method."); | ||
} | ||
|
||
void* IrSelectedRows::AllocateFrom(phi::Allocator* allocator, | ||
phi::DataType dtype, | ||
size_t requested_size, | ||
bool fake_alloc) { | ||
IR_THROW("Don't use IrSelectedRows::AllocateFrom method."); | ||
} | ||
|
||
} // namespace dialect | ||
} // namespace paddle |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (c) 2023 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. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include "paddle/phi/core/allocator.h" | ||
#include "paddle/phi/core/tensor_base.h" | ||
#include "paddle/phi/core/tensor_meta.h" | ||
|
||
namespace paddle { | ||
namespace dialect { | ||
|
||
using LoD = std::vector<std::vector<size_t>>; | ||
|
||
class IrSelectedRows | ||
: public phi::TensorBase, | ||
public phi::TypeInfoTraits<phi::TensorBase, IrSelectedRows> { | ||
public: | ||
IrSelectedRows() = default; | ||
|
||
IrSelectedRows(phi::DataType dtype, | ||
const phi::DDim& dims, | ||
phi::DataLayout layout, | ||
const LoD& lod, | ||
size_t offset = 0); | ||
|
||
IrSelectedRows(IrSelectedRows&& other) = default; | ||
|
||
IrSelectedRows(const IrSelectedRows& other); | ||
|
||
IrSelectedRows& operator=(const IrSelectedRows& other); | ||
|
||
IrSelectedRows& operator=(IrSelectedRows&& other) noexcept; | ||
|
||
virtual ~IrSelectedRows() = default; | ||
|
||
public: | ||
static const char* name() { return "IrSelectedRows"; } | ||
|
||
int64_t numel() const override; | ||
|
||
const phi::DDim& dims() const noexcept override { return dims_; } | ||
|
||
void SetDims(const phi::DDim& dims) { dims_ = dims; } | ||
|
||
const phi::Place& place() const override; | ||
|
||
phi::DataType dtype() const noexcept override { return dtype_; } | ||
|
||
void SetDtype(phi::DataType dtype) { dtype_ = dtype; } | ||
|
||
phi::DataLayout layout() const noexcept override { return layout_; } | ||
|
||
void SetLayout(phi::DataLayout layout) { layout_ = layout; } | ||
|
||
const LoD& lod() const noexcept { return lod_; } | ||
|
||
void SetLod(LoD lod) { lod_ = lod; } | ||
|
||
size_t offset() const noexcept { return offset_; } | ||
|
||
bool valid() const noexcept override { return true; } | ||
|
||
bool initialized() const override { return true; } | ||
|
||
void* AllocateFrom(phi::Allocator* allocator, | ||
phi::DataType dtype, | ||
size_t requested_size = 0, | ||
bool fake_alloc = false) override; | ||
|
||
private: | ||
phi::DDim dims_; | ||
phi::DataType dtype_{phi::DataType::FLOAT32}; | ||
phi::DataLayout layout_{phi::DataLayout::ANY}; | ||
LoD lod_; | ||
size_t offset_{0}; | ||
}; | ||
|
||
} // namespace dialect | ||
} // namespace paddle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
下面这几个构造函数是不是都可以用=default 就可以了。因为成员里没有指针对象,默认的应该够用?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感谢建议,单独 pr 完善一下~