diff --git a/cmake/external/pybind11.cmake b/cmake/external/pybind11.cmake index 1e0838145a63d268f03f755839b38ccc4afdd610..6ce8290d72f4247eca7b3cc7b59faa63aaa44486 100644 --- a/cmake/external/pybind11.cmake +++ b/cmake/external/pybind11.cmake @@ -24,7 +24,7 @@ set(SOURCE_INCLUDE_DIR ${SOURCE_DIR}/include) include_directories(${PYBIND_INCLUDE_DIR}) set(PYBIND_PATCH_COMMAND "") -if(NOT WIN32 AND NOT CINN_ONLY) +if(NOT WIN32) file(TO_NATIVE_PATH ${PADDLE_SOURCE_DIR}/patches/pybind/cast.h.patch native_dst) # Note: [Why calling some `git` commands before `patch`?] diff --git a/paddle/cinn/CMakeLists.txt b/paddle/cinn/CMakeLists.txt index deb060eb720147984dfd4f294edec422ad99b46a..84912f18cbc509a4537a0d6b40c9ca498a291c96 100644 --- a/paddle/cinn/CMakeLists.txt +++ b/paddle/cinn/CMakeLists.txt @@ -12,9 +12,7 @@ add_subdirectory(backends) add_subdirectory(lang) add_subdirectory(optim) add_subdirectory(hlir) -if(CINN_ONLY) - add_subdirectory(pybind) -endif() +add_subdirectory(pybind) add_subdirectory(frontend) # Download a model diff --git a/paddle/cinn/pybind/bind_utils.h b/paddle/cinn/pybind/bind_utils.h index 71374d41e1205b7813c729bae3a796c926d1bcd2..397ee42dd4bf17cd065291ad00addade25c254b0 100644 --- a/paddle/cinn/pybind/bind_utils.h +++ b/paddle/cinn/pybind/bind_utils.h @@ -179,23 +179,8 @@ void DefineUnaryOpNode(py::module *m, absl::string_view node_name) { py::return_value_policy::reference); } -class ObjectWrapper : public Object { - public: - using Object::Object; - - const char *type_info() const override { - PYBIND11_OVERLOAD_PURE(const char *, Object, type_info); - } -}; - class IrNodeWrapper : ir::IrNode { using ir::IrNode::IrNode; }; -class _Operation_Wrapper : ir::_Operation_ { - public: - const char *func_type() const override { - PYBIND11_OVERLOAD_PURE(const char *, ir::_Operation_, func_type); - } -}; } // namespace cinn::pybind diff --git a/paddle/cinn/pybind/common.cc b/paddle/cinn/pybind/common.cc index a39d51628df09002d3d18de7143be3286f3eb8a7..b2ae44f82d591cf26f54d238107512329b9f3584 100644 --- a/paddle/cinn/pybind/common.cc +++ b/paddle/cinn/pybind/common.cc @@ -30,7 +30,6 @@ namespace cinn::pybind { using common::bfloat16; using common::CINNValue; using common::float16; -using common::Object; using common::Target; using common::Type; using utils::GetStreamCnt; @@ -39,7 +38,6 @@ using utils::StringFormat; namespace { void BindTarget(py::module *); void BindType(py::module *); -void BindObject(py::module *); void BindShared(py::module *); void BindCinnValue(py::module *); @@ -208,11 +206,6 @@ void BindType(py::module *m) { }); } -void BindObject(py::module *m) { - py::class_ object(*m, "Object"); - object.def("type_info", &Object::type_info); -} - void BindShared(py::module *m) { py::class_ ref_count(*m, "RefCount"); ref_count.def(py::init<>()) @@ -367,7 +360,6 @@ void BindCinnValue(py::module *m) { void BindCommon(py::module *m) { BindTarget(m); BindType(m); - BindObject(m); BindShared(m); BindCinnValue(m); } diff --git a/paddle/cinn/pybind/ir.cc b/paddle/cinn/pybind/ir.cc old mode 100755 new mode 100644 index a79da48c887270aa9fe561e4ed1e8d56867789e5..d073f4b75e78c20685502bf53b490e97ca16506d --- a/paddle/cinn/pybind/ir.cc +++ b/paddle/cinn/pybind/ir.cc @@ -108,7 +108,7 @@ void BindNode(py::module *m) { #undef DECLARE_IR_NODE_TY // class IrNode - py::class_ ir_node( + py::class_ ir_node( *m, "IrNode", py::module_local()); ir_node.def(py::init<>()) .def(py::init()) @@ -539,14 +539,13 @@ void BindIrIr(py::module *m) { } void BindOperation(py::module *m) { - py::class_ placeholder_op( - *m, "PlaceholderOp"); + py::class_ placeholder_op(*m, "PlaceholderOp"); placeholder_op.def_readwrite("shape", &ir::PlaceholderOp::shape) .def_readwrite("dtype", &ir::PlaceholderOp::dtype) .def_static("make", &ir::PlaceholderOp::Make) .def("func_type", &ir::PlaceholderOp::func_type); - py::class_ call_op(*m, "CallOp"); + py::class_ call_op(*m, "CallOp"); call_op.def("target", &ir::CallOp::target) .def_readwrite("call_expr", &ir::CallOp::call_expr) .def("read_args_mutable", py::overload_cast<>(&ir::CallOp::read_args)) @@ -564,8 +563,7 @@ void BindOperation(py::module *m) { .def_static("make", &ir::CallOp::Make) .def("func_type", &ir::CallOp::func_type); - py::class_ compute_op(*m, - "ComputeOp"); + py::class_ compute_op(*m, "ComputeOp"); compute_op.def_readwrite("reduce_axis", &ir::ComputeOp::reduce_axis) .def_readwrite("shape", &ir::ComputeOp::shape) .def_readwrite("body", &ir::ComputeOp::body) diff --git a/paddle/cinn/pybind/poly.cc b/paddle/cinn/pybind/poly.cc index e9e0edba2fd3b4b7fa09641f9e6eb84eb14a9c78..55bdf7661c0c354f746ef3cf94fe80541caf600d 100644 --- a/paddle/cinn/pybind/poly.cc +++ b/paddle/cinn/pybind/poly.cc @@ -69,7 +69,7 @@ void BindStageMap(py::module *m) { } void BindStage(py::module *m) { - py::class_ stage(*m, "Stage"); + py::class_ stage(*m, "Stage"); // enum Stage::ComputeAtKind py::enum_ compute_at_kind(stage, "ComputeAtKind"); compute_at_kind.value("kComputeAtUnk", Stage::ComputeAtKind::kComputeAtAuto) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index cd7dc7e12f2a3554895361033699a4cf8c8d45af..a96f541580eb36268315bae22e9590562717a562 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,4 +1,4 @@ -if(CINN_ONLY) +if(WITH_CINN) file(GLOB_RECURSE CINN_PY_FILES ${PROJECT_SOURCE_DIR}/python/cinn/*.py) set(CINN_PYTHON_DIR ${PROJECT_SOURCE_DIR}/python/cinn) set(CINN_CORE_API ${CMAKE_BINARY_DIR}/python/cinn/core_api.so) @@ -24,8 +24,8 @@ if(CINN_ONLY) # then core_api.so. add_custom_command( OUTPUT ${CINN_CORE_API} POST_BUILD - COMMAND cp -rf --remove-destination ${CINN_PYTHON_DIR} - ${CMAKE_BINARY_DIR}/python/cinn + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CINN_PYTHON_DIR} + ${PADDLE_BINARY_DIR}/python/cinn COMMAND cp --remove-destination ${CMAKE_BINARY_DIR}/paddle/cinn/pybind/core_api.so ${CINN_CORE_API} COMMAND cd ${CMAKE_CURRENT_BINARY_DIR} && ${PYTHON_EXECUTABLE} setup_cinn.py @@ -35,7 +35,9 @@ if(CINN_ONLY) add_custom_target(COPY_CINN_CORE_API ALL DEPENDS ${CINN_CORE_API} ${CINN_PY_FILES}) - return() + if(CINN_ONLY) + return() + endif() endif() file(GLOB UTILS_PY_FILES . ./paddle/legacy/utils/*.py) diff --git a/python/setup_cinn.py.in b/python/setup_cinn.py.in index 832d9610d0288f7fa08e6262b156c5b50dd9b3fb..1dea28ce5afe5b9dfa364f44b135a529bbe63520 100644 --- a/python/setup_cinn.py.in +++ b/python/setup_cinn.py.in @@ -127,6 +127,7 @@ else: yield libs_path = '${CMAKE_BINARY_DIR}/python/cinn/libs' +os.makedirs(libs_path, exist_ok=True) cinnlibs = [] package_data = {'cinn': ['core_api.so'], 'cinn.libs': []} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 613e3807265a74ef949dad0bd6cc2c2a1f892394..ae097ef6d9b725e3ab41c68f0b3f72e2573ced78 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -93,11 +93,12 @@ endfunction() if(WITH_TESTING) if(WITH_CINN) add_subdirectory(cpp/cinn) + add_subdirectory(cinn) endif() if(CINN_ONLY) - add_subdirectory(cinn) return() endif() + add_subdirectory(amp) add_subdirectory(asp) add_subdirectory(autograd)