-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refine code * delete some unused code * refine code of build * refine code of build * add block * refine builder * refine code * refine code by comment * fix compiler bug
- Loading branch information
1 parent
1549fbd
commit 3143d8b
Showing
18 changed files
with
288 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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/ir/block.h" | ||
|
||
namespace ir { | ||
Block::~Block() { clear(); } | ||
|
||
void Block::clear() { | ||
while (!empty()) { | ||
ops_.back()->destroy(); | ||
ops_.pop_back(); | ||
} | ||
} | ||
} // namespace ir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// 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 <list> | ||
#include "paddle/ir/operation.h" | ||
|
||
namespace ir { | ||
class Block { | ||
public: | ||
using iterator = std::list<Operation *>::iterator; | ||
using reverse_iterator = std::list<Operation *>::reverse_iterator; | ||
|
||
Block() = default; | ||
~Block(); | ||
|
||
bool empty() const { return ops_.empty(); } | ||
size_t size() const { return ops_.size(); } | ||
|
||
iterator begin() { return ops_.begin(); } | ||
iterator end() { return ops_.end(); } | ||
reverse_iterator rbegin() { return ops_.rbegin(); } | ||
reverse_iterator rend() { return ops_.rend(); } | ||
|
||
Operation *back() { return ops_.back(); } | ||
Operation *front() { return ops_.front(); } | ||
void push_back(Operation *op) { ops_.push_back(op); } | ||
void push_front(Operation *op) { ops_.push_front(op); } | ||
std::list<Operation *>::iterator insert( | ||
std::list<Operation *>::const_iterator iterator, Operation *op) { | ||
return ops_.insert(iterator, op); | ||
} | ||
void clear(); | ||
|
||
private: | ||
Block(Block &) = delete; | ||
void operator=(Block &) = delete; | ||
|
||
private: | ||
std::list<Operation *> ops_; // owned | ||
}; | ||
} // namespace ir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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/ir/builder.h" | ||
|
||
namespace ir { | ||
Operation *Builder::insert(Operation *op) { | ||
if (block_) { | ||
block_->insert(insert_point_, op); | ||
} else { | ||
LOG(WARNING) << "Builder's Block is nullptr, insert failed."; | ||
} | ||
return op; | ||
} | ||
|
||
/// Create an operation given the fields represented as an OperationState. | ||
Operation *Builder::create(const OperationArgument &argument) { | ||
return insert(Operation::create(argument)); | ||
} | ||
|
||
/// Creates an operation with the given fields. | ||
Operation *Builder::create(const std::vector<ir::OpResult> &inputs, | ||
const std::vector<ir::Type> &output_types, | ||
const AttributeMap &attribute, | ||
ir::OpInfo op_info) { | ||
OperationArgument argument(op_info, inputs, output_types, attribute); | ||
return create(argument); | ||
} | ||
|
||
} // namespace ir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.