Skip to content

Commit

Permalink
[NewIR]Rename ir into pir and Adjust Dialect class name (#57103)
Browse files Browse the repository at this point in the history
* [NewIR]Rename ir into pir and Adjust Dialect class name

* fix merge error

* fix merge conflict

* fix conflict

* fix error

* fix code style

* fix pd dialect name error

* fix merge conflict

* fix UT

* fix ArrayAttribute<Int64>

* fix new_interpreter

* fix patter_rewrite UT
  • Loading branch information
Aurelius84 authored Sep 9, 2023
1 parent 7727108 commit 3d6606e
Show file tree
Hide file tree
Showing 354 changed files with 5,219 additions and 5,161 deletions.
8 changes: 4 additions & 4 deletions cmake/cinn.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ cinn_cc_library(
add_dependencies(cinnapi GEN_LLVM_RUNTIME_IR_HEADER ZLIB::ZLIB)
add_dependencies(cinnapi GEN_LLVM_RUNTIME_IR_HEADER ${core_deps})
if(NOT CINN_ONLY)
target_link_libraries(cinnapi pd_dialect phi)
add_dependencies(cinnapi pd_dialect phi)
target_link_libraries(cinnapi pd_op_dialect phi)
add_dependencies(cinnapi pd_op_dialect phi)
endif()

target_link_libraries(cinnapi ${PYTHON_LIBRARIES})
Expand Down Expand Up @@ -222,8 +222,8 @@ function(gen_cinncore LINKTYPE)
add_dependencies(${CINNCORE_TARGET} GEN_LLVM_RUNTIME_IR_HEADER ZLIB::ZLIB)
add_dependencies(${CINNCORE_TARGET} GEN_LLVM_RUNTIME_IR_HEADER ${core_deps})
if(NOT CINN_ONLY)
target_link_libraries(${CINNCORE_TARGET} pd_dialect phi)
add_dependencies(${CINNCORE_TARGET} pd_dialect phi)
target_link_libraries(${CINNCORE_TARGET} pd_op_dialect phi)
add_dependencies(${CINNCORE_TARGET} pd_op_dialect phi)
endif()

add_dependencies(${CINNCORE_TARGET} pybind)
Expand Down
4 changes: 2 additions & 2 deletions cmake/inference_lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ else()
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/lib)
endif()
if(WITH_SHARED_IR)
set(paddle_ir_lib ${PADDLE_BINARY_DIR}/paddle/ir/libir.*)
set(paddle_pir_lib ${PADDLE_BINARY_DIR}/paddle/pir/libpir.*)
copy(
inference_lib_dist
SRCS ${paddle_ir_lib}
SRCS ${paddle_pir_lib}
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/lib)
endif()
endif()
Expand Down
2 changes: 1 addition & 1 deletion paddle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(PYTHON_TESTS_DIR
CACHE INTERNAL "python tests directory")

add_subdirectory(utils)
add_subdirectory(ir)
add_subdirectory(pir)
add_subdirectory(scripts)
add_subdirectory(testing)
add_subdirectory(phi)
Expand Down
4 changes: 2 additions & 2 deletions paddle/cinn/hlir/dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_subdirectory(cinn_dialect)
add_subdirectory(runtime_dialect)
add_subdirectory(operator)
add_subdirectory(runtime)
31 changes: 0 additions & 31 deletions paddle/cinn/hlir/dialect/generated/cinn_ops.parsed.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
# TODO(Aurelius84): new_ir_compiler depends on pd_dialect and could
# TODO(Aurelius84): new_ir_compiler depends on pd_op_dialect and could
# not found under CINN_ONLY mode
if(NOT CINN_ONLY)
set(CINN_DIALECT_BINARY_DIR
"${PADDLE_BINARY_DIR}/paddle/cinn/hlir/dialect/cinn_dialect/ir")
"${PADDLE_BINARY_DIR}/paddle/cinn/hlir/dialect/operator/ir")

# Generate cinn_dialect files defining op using op_gen_file
# Generate cinn_op_dialect files defining op using op_gen_file
set(cinn_op_gen_parsed_yaml_file
${PADDLE_SOURCE_DIR}/paddle/fluid/operators/generator/parse_op.py)

set(cinn_op_gen_file
${PADDLE_SOURCE_DIR}/paddle/fluid/ir/dialect/op_generator/op_gen.py)
${PADDLE_SOURCE_DIR}/paddle/fluid/pir/dialect/op_generator/op_gen.py)

set(cinn_op_compat_yaml_file
${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml)

set(cinn_op_yaml_file
${PADDLE_SOURCE_DIR}/paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_ops.yaml
)
${PADDLE_SOURCE_DIR}/paddle/cinn/hlir/dialect/operator/ir/ops.yaml)

set(parsed_op_dir ${PADDLE_SOURCE_DIR}/paddle/cinn/hlir/dialect/generated)

set(cinn_op_parsed_yaml_file ${parsed_op_dir}/cinn_ops.parsed.yaml)
set(cinn_op_parsed_yaml_file ${parsed_op_dir}/ops.parsed.yaml)

set(cinn_op_parsed_yaml_files ${cinn_op_parsed_yaml_file})

set(cinn_op_namespace cinn,dialect)
set(cinn_dialect_name cinn)
set(cinn_op_dialect_name cinn_op)
set(cinn_op_header_file ${CINN_DIALECT_BINARY_DIR}/cinn_op.h)
set(cinn_op_source_file ${CINN_DIALECT_BINARY_DIR}/cinn_op.cc)
set(cinn_op_header_file_tmp ${cinn_op_header_file}.tmp)
Expand All @@ -44,7 +43,7 @@ if(NOT CINN_ONLY)
${PYTHON_EXECUTABLE} ${cinn_op_gen_file} --op_yaml_files
${cinn_op_parsed_yaml_files} --op_compat_yaml_file
${cinn_op_compat_yaml_file} --namespaces ${cinn_op_namespace}
--dialect_name ${cinn_dialect_name} --op_def_h_file
--dialect_name ${cinn_op_dialect_name} --op_def_h_file
${cinn_op_header_file_tmp} --op_def_cc_file ${cinn_op_source_file_tmp}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cinn_op_header_file_tmp}
${cinn_op_header_file}
Expand All @@ -54,8 +53,8 @@ if(NOT CINN_ONLY)
${cinn_op_compat_yaml_file}
VERBATIM)

cinn_cc_library(cinn_dialect SRCS cinn_dialect.cc ${cinn_op_source_file} DEPS
pd_dialect)
cinn_cc_library(cinn_op_dialect SRCS op_dialect.cc ${cinn_op_source_file}
DEPS pd_op_dialect)

target_include_directories(cinn_dialect PRIVATE ${CINN_DIALECT_BINARY_DIR})
target_include_directories(cinn_op_dialect PRIVATE ${CINN_DIALECT_BINARY_DIR})
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,32 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_dialect.h"
#include "paddle/cinn/hlir/dialect/operator/ir/op_dialect.h"
// NOTE(chenxi67): File cinn_op.h is generated by op_gen.py, see details in
// paddle/cinn/hlir/dialect/CMakeLists.txt.
#include "paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_op.h"
#include "paddle/cinn/hlir/dialect/operator/ir/cinn_op.h"

namespace cinn {
namespace dialect {

CinnDialect::CinnDialect(::ir::IrContext* context)
: ::ir::Dialect(
name(), context, ::ir::TypeId::get<cinn::dialect::CinnDialect>()) {
OperatorDialect::OperatorDialect(::pir::IrContext* context)
: ::pir::Dialect(name(),
context,
::pir::TypeId::get<cinn::dialect::OperatorDialect>()) {
this->initialize();
}

void CinnDialect::initialize() {
void OperatorDialect::initialize() {
// NOTE(chenxi67): GET_OP_LIST is defined in cinn_op.h which is
// generated by op_gen.py, see details in
// paddle/cinn/hlir/dialect/CMakeLists.txt.
RegisterOps<
#define GET_OP_LIST
#include "paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_op.h" // NOLINT
#include "paddle/cinn/hlir/dialect/operator/ir/cinn_op.h" // NOLINT
>();
}

} // namespace dialect
} // namespace cinn

IR_DEFINE_EXPLICIT_TYPE_ID(cinn::dialect::CinnDialect)
IR_DEFINE_EXPLICIT_TYPE_ID(cinn::dialect::OperatorDialect)
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

#pragma once

#include "paddle/ir/core/dialect.h"
#include "paddle/pir/core/dialect.h"

namespace cinn {
namespace dialect {

class CinnDialect : public ::ir::Dialect {
class OperatorDialect : public ::pir::Dialect {
public:
explicit CinnDialect(::ir::IrContext* context);
explicit OperatorDialect(::pir::IrContext* context);

static const char* name() { return "cinn"; }
static const char* name() { return "cinn_op"; }

private:
void initialize();
Expand All @@ -32,4 +32,4 @@ class CinnDialect : public ::ir::Dialect {
} // namespace dialect
} // namespace cinn

IR_DECLARE_EXPLICIT_TYPE_ID(cinn::dialect::CinnDialect)
IR_DECLARE_EXPLICIT_TYPE_ID(cinn::dialect::OperatorDialect)
4 changes: 4 additions & 0 deletions paddle/cinn/hlir/dialect/runtime/ir/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if(NOT CINN_ONLY)
cinn_cc_library(cinn_runtime_dialect SRCS runtime_dialect.cc jit_kernel_op.cc
DEPS pir_core)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/jit_kernel_op.h"
#include "paddle/cinn/hlir/dialect/runtime/ir/jit_kernel_op.h"

#include "paddle/ir/core/builtin_attribute.h"
#include "paddle/ir/core/enforce.h"
#include "paddle/pir/core/builtin_attribute.h"
#include "paddle/pir/core/enforce.h"

namespace cinn {
namespace dialect {
Expand All @@ -28,13 +28,13 @@ void JitKernelOp::Verify() {
auto& attributes = this->attributes();

IR_ENFORCE(attributes.count(kAttrName) > 0 &&
attributes.at(kAttrName).isa<::ir::PointerAttribute>(),
attributes.at(kAttrName).isa<::pir::PointerAttribute>(),
"Type of attribute: instruction is not right.");
}

hlir::framework::Instruction* JitKernelOp::instruction() {
void* ptr =
attributes().at(kAttrName).dyn_cast<ir::PointerAttribute>().data();
attributes().at(kAttrName).dyn_cast<::pir::PointerAttribute>().data();
return reinterpret_cast<hlir::framework::Instruction*>(ptr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#pragma once

#include "paddle/ir/core/op_base.h"
#include "paddle/pir/core/op_base.h"

namespace cinn {

Expand All @@ -40,10 +40,10 @@ namespace dialect {
* temporarily, and will spilt executor information like
* scope, inputs, outputs into InterpretorCore module.
*/
class JitKernelOp : public ::ir::Op<JitKernelOp> {
class JitKernelOp : public ::pir::Op<JitKernelOp> {
public:
using Op::Op;
static const char* name() { return "cinn.jit_kernel"; }
static const char* name() { return "cinn_runtime.jit_kernel"; }
// TODO(Aurelius84): Think deeply what should contains
static constexpr uint32_t attributes_num = 1;
static constexpr char* kAttrName = "instruction";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/runtime_dialect.h"
#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/jit_kernel_op.h"
#include "paddle/cinn/hlir/dialect/runtime/ir/runtime_dialect.h"
#include "paddle/cinn/hlir/dialect/runtime/ir/jit_kernel_op.h"

namespace cinn {
namespace dialect {

RuntimeDialect::RuntimeDialect(::ir::IrContext* context)
: ::ir::Dialect(
name(), context, ::ir::TypeId::get<cinn::dialect::RuntimeDialect>()) {
RuntimeDialect::RuntimeDialect(::pir::IrContext* context)
: ::pir::Dialect(name(),
context,
::pir::TypeId::get<cinn::dialect::RuntimeDialect>()) {
this->initialize();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

#pragma once

#include "paddle/ir/core/dialect.h"
#include "paddle/pir/core/dialect.h"

namespace cinn {
namespace dialect {

class RuntimeDialect : public ::ir::Dialect {
class RuntimeDialect : public ::pir::Dialect {
public:
explicit RuntimeDialect(::ir::IrContext* context);
explicit RuntimeDialect(::pir::IrContext* context);

static const char* name() { return "cinn"; }
static const char* name() { return "cinn_runtime"; }

private:
void initialize();
Expand Down
4 changes: 0 additions & 4 deletions paddle/cinn/hlir/dialect/runtime_dialect/ir/CMakeLists.txt

This file was deleted.

6 changes: 3 additions & 3 deletions paddle/cinn/hlir/framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ gather_srcs(
accuracy_checker.cc
visualize_helper.cc)

# TODO(Aurelius84): new_ir_compiler depends on pd_dialect and could
# TODO(Aurelius84): new_ir_compiler depends on pd_op_dialect and could
# not found under CINN_ONLY mode
if(NOT CINN_ONLY)
cinn_cc_library(new_ir_compiler SRCS new_ir_compiler.cc DEPS cinnapi
pd_dialect)
pd_op_dialect)
cinn_cc_library(convert_to_dialect SRCS convert_to_dialect.cc DEPS cinnapi
cinn_dialect)
cinn_op_dialect)
endif()

if(WITH_CUDA)
Expand Down
24 changes: 12 additions & 12 deletions paddle/cinn/hlir/framework/convert_to_dialect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,34 @@
#include <string>
#include <unordered_map>

#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/jit_kernel_op.h"
#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/runtime_dialect.h"
#include "paddle/cinn/hlir/dialect/runtime/ir/jit_kernel_op.h"
#include "paddle/cinn/hlir/dialect/runtime/ir/runtime_dialect.h"
#include "paddle/cinn/hlir/framework/program.h"
#include "paddle/ir/core/builtin_attribute.h"
#include "paddle/ir/core/program.h"
#include "paddle/pir/core/builtin_attribute.h"
#include "paddle/pir/core/program.h"

namespace cinn {
namespace hlir {
namespace framework {

std::unique_ptr<::ir::Program> ConvertToRuntimeDialect(
std::unique_ptr<::pir::Program> ConvertToRuntimeDialect(
const hlir::framework::Program& program) {
::ir::IrContext* ctx = ::ir::IrContext::Instance();
::pir::IrContext* ctx = ::pir::IrContext::Instance();
ctx->GetOrRegisterDialect<cinn::dialect::RuntimeDialect>();
auto ir_program = std::make_unique<::ir::Program>(ctx);
auto ir_program = std::make_unique<::pir::Program>(ctx);

std::string jit_op_name = dialect::JitKernelOp::name();
::ir::OpInfo op_info = ctx->GetRegisteredOpInfo(jit_op_name);
::pir::OpInfo op_info = ctx->GetRegisteredOpInfo(jit_op_name);

auto& instrs = program.GetRunInstructions();
for (auto& instr : instrs) {
std::unordered_map<std::string, ::ir::Attribute> op_attrs{
std::unordered_map<std::string, ::pir::Attribute> op_attrs{
{dialect::JitKernelOp::kAttrName,
::ir::PointerAttribute::get(ctx, instr.get())},
::pir::PointerAttribute::get(ctx, instr.get())},
};

::ir::Operation* cinn_op =
::ir::Operation::Create({}, op_attrs, {}, op_info);
::pir::Operation* cinn_op =
::pir::Operation::Create({}, op_attrs, {}, op_info);
ir_program->block()->push_back(cinn_op);
}
return std::move(ir_program);
Expand Down
6 changes: 3 additions & 3 deletions paddle/cinn/hlir/framework/convert_to_dialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

#include <memory>

namespace ir {
namespace pir {
class Program;
} // namespace ir
} // namespace pir

namespace cinn {
namespace hlir {
namespace framework {
class Program;

std::unique_ptr<::ir::Program> ConvertToRuntimeDialect(
std::unique_ptr<::pir::Program> ConvertToRuntimeDialect(
const hlir::framework::Program& program);

} // namespace framework
Expand Down
Loading

0 comments on commit 3d6606e

Please sign in to comment.