forked from PaddlePaddle/Paddle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the definition of ir emitter (PaddlePaddle#20)
* the definition of ir emitter * fix test * update test * remove default constuctor * remove unused head file * add ir emitter annotation
- Loading branch information
1 parent
15c3e35
commit 0422002
Showing
10 changed files
with
431 additions
and
2 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
45 changes: 45 additions & 0 deletions
45
paddle/fluid/compiler/piano/backends/llvm_ir/gpu_ir_emitter.cc
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,45 @@ | ||
// Copyright (c) 2021 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/compiler/piano/backends/llvm_ir/gpu_ir_emitter.h" | ||
|
||
namespace paddle { | ||
namespace piano { | ||
namespace backends { | ||
|
||
void GpuIrEmitter::VisitElementwiseUnary(const note::Instruction& instr) {} | ||
void GpuIrEmitter::VisitElementwiseBinary(const note::Instruction& instr) {} | ||
|
||
// Scalar op | ||
void GpuIrEmitter::VisitConstant(const note::Instruction& instr) {} | ||
|
||
// Unary | ||
void GpuIrEmitter::VisitBroadcast(const note::Instruction& instr) {} | ||
void GpuIrEmitter::VisitCopy(const note::Instruction& instr) {} | ||
void GpuIrEmitter::VisitReshape(const note::Instruction& instr) {} | ||
void GpuIrEmitter::VisitReverse(const note::Instruction& instr) {} | ||
void GpuIrEmitter::VisitSlice(const note::Instruction& instr) {} | ||
void GpuIrEmitter::VisitTranspose(const note::Instruction& instr) {} | ||
|
||
// Other | ||
void GpuIrEmitter::VisitSelect(const note::Instruction& instr) {} | ||
void GpuIrEmitter::VisitConcatenate(const note::Instruction& instr) {} | ||
void GpuIrEmitter::VisitReduce(const note::Instruction& instr) {} | ||
void GpuIrEmitter::VisitRng(const note::Instruction& instr) {} | ||
void GpuIrEmitter::VisitSort(const note::Instruction& instr) {} | ||
void GpuIrEmitter::VisitTuple(const note::Instruction& instr) {} | ||
|
||
} // namespace backends | ||
} // namespace piano | ||
} // namespace paddle |
65 changes: 65 additions & 0 deletions
65
paddle/fluid/compiler/piano/backends/llvm_ir/gpu_ir_emitter.h
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,65 @@ | ||
// Copyright (c) 2021 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/fluid/compiler/piano/backends/llvm_ir/ir_emitter.h" | ||
|
||
namespace paddle { | ||
namespace piano { | ||
namespace backends { | ||
|
||
// GpuIrEmitter is for translating note::Instruction to llvm IR | ||
// for GPU. | ||
// It implement the visit function for note::Instruction's translation。 | ||
|
||
class GpuIrEmitter : public IrEmitter { | ||
public: | ||
GpuIrEmitter() = delete; | ||
explicit GpuIrEmitter(llvm::Module* llvm_module, Schedules* schedule) | ||
: IrEmitter(llvm_module, schedule) {} | ||
virtual ~GpuIrEmitter() {} | ||
|
||
void VisitElementwiseUnary(const note::Instruction&) override; | ||
void VisitElementwiseBinary(const note::Instruction&) override; | ||
|
||
// Scalar op | ||
void VisitConstant(const note::Instruction&) override; | ||
|
||
// ops can be replaced by library | ||
virtual void VisitBatchNormGrad(const note::Instruction&) = 0; | ||
virtual void VisitBatchNormInference(const note::Instruction&) = 0; | ||
virtual void VisitBatchNormTraining(const note::Instruction&) = 0; | ||
virtual void VisitConvolution(const note::Instruction&) = 0; | ||
virtual void VisitDot(const note::Instruction&) = 0; | ||
|
||
// Unary | ||
void VisitBroadcast(const note::Instruction&) override; | ||
void VisitCopy(const note::Instruction&) override; | ||
void VisitReshape(const note::Instruction&) override; | ||
void VisitReverse(const note::Instruction&) override; | ||
void VisitSlice(const note::Instruction&) override; | ||
void VisitTranspose(const note::Instruction&) override; | ||
|
||
// Other | ||
void VisitSelect(const note::Instruction&) override; | ||
void VisitConcatenate(const note::Instruction&) override; | ||
void VisitReduce(const note::Instruction&) override; | ||
void VisitRng(const note::Instruction&) override; | ||
void VisitSort(const note::Instruction&) override; | ||
void VisitTuple(const note::Instruction&) override; | ||
}; | ||
|
||
} // namespace backends | ||
} // namespace piano | ||
} // namespace paddle |
76 changes: 76 additions & 0 deletions
76
paddle/fluid/compiler/piano/backends/llvm_ir/ir_emitter.cc
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,76 @@ | ||
// Copyright (c) 2021 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/compiler/piano/backends/llvm_ir/ir_emitter.h" | ||
|
||
namespace paddle { | ||
namespace piano { | ||
namespace backends { | ||
|
||
void IrEmitter::VisitCast(const note::Instruction& instr) { | ||
VisitElementwiseUnary(instr); | ||
} | ||
void IrEmitter::VisitExp(const note::Instruction& instr) { | ||
VisitElementwiseUnary(instr); | ||
} | ||
void IrEmitter::VisitLog(const note::Instruction& instr) { | ||
VisitElementwiseUnary(instr); | ||
} | ||
void IrEmitter::VisitNegative(const note::Instruction& instr) { | ||
VisitElementwiseUnary(instr); | ||
} | ||
void IrEmitter::VisitNot(const note::Instruction& instr) { | ||
VisitElementwiseUnary(instr); | ||
} | ||
void IrEmitter::VisitRsqrt(const note::Instruction& instr) { | ||
VisitElementwiseUnary(instr); | ||
} | ||
void IrEmitter::VisitSqrt(const note::Instruction& instr) { | ||
VisitElementwiseUnary(instr); | ||
} | ||
|
||
void IrEmitter::VisitAdd(const note::Instruction& instr) { | ||
VisitElementwiseBinary(instr); | ||
} | ||
void IrEmitter::VisitAnd(const note::Instruction& instr) { | ||
VisitElementwiseBinary(instr); | ||
} | ||
void IrEmitter::VisitCompare(const note::Instruction& instr) { | ||
VisitElementwiseBinary(instr); | ||
} | ||
void IrEmitter::VisitDivide(const note::Instruction& instr) { | ||
VisitElementwiseBinary(instr); | ||
} | ||
void IrEmitter::VisitMaximum(const note::Instruction& instr) { | ||
VisitElementwiseBinary(instr); | ||
} | ||
void IrEmitter::VisitMinimum(const note::Instruction& instr) { | ||
VisitElementwiseBinary(instr); | ||
} | ||
void IrEmitter::VisitMultiply(const note::Instruction& instr) { | ||
VisitElementwiseBinary(instr); | ||
} | ||
void IrEmitter::VisitOr(const note::Instruction& instr) { | ||
VisitElementwiseBinary(instr); | ||
} | ||
void IrEmitter::VisitSubtract(const note::Instruction& instr) { | ||
VisitElementwiseBinary(instr); | ||
} | ||
void IrEmitter::VisitXor(const note::Instruction& instr) { | ||
VisitElementwiseBinary(instr); | ||
} | ||
|
||
} // namespace backends | ||
} // namespace piano | ||
} // namespace paddle |
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,99 @@ | ||
// Copyright (c) 2021 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 "llvm/IR/Module.h" | ||
#include "paddle/fluid/compiler/piano/backends/note_visitor_base.h" | ||
#include "paddle/fluid/compiler/piano/backends/schedule_wrapper.h" | ||
|
||
namespace paddle { | ||
namespace piano { | ||
namespace backends { | ||
|
||
// IrEmitter is an Abstract base class for translating note::Instruction to llvm | ||
// IR. | ||
// To translating note::Instruction to llvm IR for special device, it should | ||
// inherit from IrEmitter and overwrite the virtual function. | ||
// note::Instruction has different type {Scalar Op, Api Op, Unary Op, Binary Op, | ||
// Others} | ||
// Elementwise-Unary Op and Elementwise-Binary Op should be implemented | ||
// in VisitElementwiseUnary and VisitElementwiseBinary. | ||
|
||
class IrEmitter : public NoteVisitorBase { | ||
public: | ||
IrEmitter() = delete; | ||
explicit IrEmitter(llvm::Module* llvm_module, Schedules* schedule) | ||
: llvm_module_(llvm_module), schedules_(schedule) {} | ||
virtual ~IrEmitter() {} | ||
|
||
// ElementwiseUnary Operator | ||
virtual void VisitElementwiseUnary(const note::Instruction&) = 0; | ||
// ElementwiseBinary Operator | ||
virtual void VisitElementwiseBinary(const note::Instruction&) = 0; | ||
|
||
// Scalar op | ||
virtual void VisitConstant(const note::Instruction&) = 0; | ||
|
||
// ops can be replaced by library | ||
virtual void VisitBatchNormGrad(const note::Instruction&) = 0; | ||
virtual void VisitBatchNormInference(const note::Instruction&) = 0; | ||
virtual void VisitBatchNormTraining(const note::Instruction&) = 0; | ||
virtual void VisitConvolution(const note::Instruction&) = 0; | ||
virtual void VisitDot(const note::Instruction&) = 0; | ||
|
||
// Unary | ||
virtual void VisitBroadcast(const note::Instruction&) = 0; | ||
virtual void VisitCopy(const note::Instruction&) = 0; | ||
virtual void VisitReshape(const note::Instruction&) = 0; | ||
virtual void VisitReverse(const note::Instruction&) = 0; | ||
virtual void VisitSlice(const note::Instruction&) = 0; | ||
virtual void VisitTranspose(const note::Instruction&) = 0; | ||
|
||
// Unary Compute | ||
void VisitCast(const note::Instruction&) override; | ||
void VisitExp(const note::Instruction&) override; | ||
void VisitLog(const note::Instruction&) override; | ||
void VisitNegative(const note::Instruction&) override; | ||
void VisitNot(const note::Instruction&) override; | ||
void VisitRsqrt(const note::Instruction&) override; | ||
void VisitSqrt(const note::Instruction&) override; | ||
|
||
// Binary | ||
void VisitAdd(const note::Instruction&) override; | ||
void VisitAnd(const note::Instruction&) override; | ||
void VisitCompare(const note::Instruction&) override; | ||
void VisitDivide(const note::Instruction&) override; | ||
void VisitMaximum(const note::Instruction&) override; | ||
void VisitMinimum(const note::Instruction&) override; | ||
void VisitMultiply(const note::Instruction&) override; | ||
void VisitOr(const note::Instruction&) override; | ||
void VisitSubtract(const note::Instruction&) override; | ||
void VisitXor(const note::Instruction&) override; | ||
|
||
// Other | ||
virtual void VisitSelect(const note::Instruction&) = 0; | ||
virtual void VisitConcatenate(const note::Instruction&) = 0; | ||
virtual void VisitReduce(const note::Instruction&) = 0; | ||
virtual void VisitRng(const note::Instruction&) = 0; | ||
virtual void VisitSort(const note::Instruction&) = 0; | ||
virtual void VisitTuple(const note::Instruction&) = 0; | ||
|
||
protected: | ||
llvm::Module* llvm_module_{nullptr}; | ||
Schedules* schedules_{nullptr}; | ||
}; | ||
|
||
} // namespace backends | ||
} // namespace piano | ||
} // namespace paddle |
29 changes: 29 additions & 0 deletions
29
paddle/fluid/compiler/piano/backends/llvm_ir/nvptx_ir_emitter.cc
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,29 @@ | ||
// Copyright (c) 2021 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/compiler/piano/backends/llvm_ir/nvptx_ir_emitter.h" | ||
|
||
namespace paddle { | ||
namespace piano { | ||
namespace backends { | ||
|
||
void NvptxIrEmitter::VisitBatchNormGrad(const note::Instruction& instr) {} | ||
void NvptxIrEmitter::VisitBatchNormInference(const note::Instruction& instr) {} | ||
void NvptxIrEmitter::VisitBatchNormTraining(const note::Instruction& instr) {} | ||
void NvptxIrEmitter::VisitConvolution(const note::Instruction& instr) {} | ||
void NvptxIrEmitter::VisitDot(const note::Instruction& instr) {} | ||
|
||
} // namespace backends | ||
} // namespace piano | ||
} // namespace paddle |
41 changes: 41 additions & 0 deletions
41
paddle/fluid/compiler/piano/backends/llvm_ir/nvptx_ir_emitter.h
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) 2021 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/fluid/compiler/piano/backends/llvm_ir/gpu_ir_emitter.h" | ||
|
||
namespace paddle { | ||
namespace piano { | ||
namespace backends { | ||
|
||
// NvptxIrEmitter is used for note::Instruction's implementation with cudnn and | ||
// cublas. | ||
|
||
class NvptxIrEmitter : public GpuIrEmitter { | ||
public: | ||
NvptxIrEmitter() = delete; | ||
explicit NvptxIrEmitter(llvm::Module* llvm_module, Schedules* schedule) | ||
: GpuIrEmitter(llvm_module, schedule) {} | ||
~NvptxIrEmitter() {} | ||
|
||
void VisitBatchNormGrad(const note::Instruction&) override; | ||
void VisitBatchNormInference(const note::Instruction&) override; | ||
void VisitBatchNormTraining(const note::Instruction&) override; | ||
void VisitConvolution(const note::Instruction&) override; | ||
void VisitDot(const note::Instruction&) override; | ||
}; | ||
|
||
} // namespace backends | ||
} // namespace piano | ||
} // namespace paddle |
Oops, something went wrong.