提交 cd5113c1 编写于 作者: Y Yu Yang

Init commit

上级 f49fda5e
......@@ -125,17 +125,17 @@ class OpRegistry {
return op;
}
static std::unordered_map<std::string, OpProto>& protos() {
static std::unordered_map<std::string, OpProto> protos_;
return protos_;
};
private:
static std::unordered_map<std::string, OpCreator>& creators() {
static std::unordered_map<std::string, OpCreator> creators_;
return creators_;
}
static std::unordered_map<std::string, OpProto>& protos() {
static std::unordered_map<std::string, OpProto> protos_;
return protos_;
};
static std::unordered_map<std::string, OpAttrChecker>& op_checkers() {
static std::unordered_map<std::string, OpAttrChecker> op_checkers_;
return op_checkers_;
......
cc_library(paddle_pybind SHARED SRCS pybind.cc DEPS pybind python)
cc_library(paddle_pybind SHARED SRCS pybind.cc DEPS pybind python add_op)
......@@ -13,12 +13,16 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include <Python.h>
#include <paddle/framework/op_registry.h>
#include <paddle/framework/scope.h>
#include <pybind11/pybind11.h>
#include <vector>
namespace py = pybind11;
namespace pd = paddle::framework;
USE_OP(add_two);
PYBIND11_PLUGIN(core) {
py::module m("core", "C++ core of Paddle Paddle");
......@@ -43,5 +47,17 @@ All parameter, weight, gradient are variables in Paddle.
&pd::Scope::CreateVariable,
py::return_value_policy::reference);
m.def("get_all_op_protos", []() -> std::vector<std::string> {
auto& protos = pd::OpRegistry::protos();
std::vector<std::string> ret_values;
ret_values.reserve(protos.size());
for (auto it = protos.begin(); it != protos.end(); ++it) {
ret_values.emplace_back();
PADDLE_ENFORCE(it->second.SerializeToString(&ret_values.back()),
"Serialize OpProto Error. This could be a bug of Paddle.");
}
return ret_values;
});
return m.ptr();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册