MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / init_tensor

Function init_tensor

imperative/python/src/tensor.cpp:874–1989  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

872#endif
873
874void init_tensor(py::module m) {
875 imperative::Tensor::static_initialize();
876 init_backtrace_tss_key();
877 // Transformations
878 static auto& transformations = TransformationManager::get_instance();
879
880 using Segment = TransformationManager::Segment;
881
882 using Channel = interpreter::Interpreter::Channel;
883
884 auto* channel =
885 imperative::ResourceManager::create_global<std::unique_ptr<Channel>>(
886 interpreter::Interpreter::inst().create_channel())
887 ->get();
888 interpreter_for_py = channel;
889 MGB_MARK_USED_VAR(
890 transformations
891 .register_at<Segment::Eval>(
892 std::make_shared<InterpreterTransformation>(
893 std::shared_ptr<Channel>(channel, [](Channel*) {})))
894 .release());
895 MGB_MARK_USED_VAR(transformations
896 .register_at<Segment::Scalar>(
897 std::make_shared<ScalarTransformation>())
898 .release());
899 MGB_MARK_USED_VAR(transformations
900 .register_at<Segment::Symbol>(
901 std::make_shared<SymbolTransformation>())
902 .release());
903 MGB_MARK_USED_VAR(transformations
904 .register_at<Segment::DTypePromote>(
905 std::make_shared<DTypePromoteTransformation>())
906 .release());
907 MGB_MARK_USED_VAR(transformations
908 .register_at<Segment::DimExpansion>(
909 std::make_shared<DimExpansionTransformation>())
910 .release());
911 MGB_MARK_USED_VAR(transformations
912 .register_at<Segment::Complex>(
913 std::make_shared<ComplexTransformation>())
914 .release());
915 MGB_MARK_USED_VAR(transformations
916 .register_at<Segment::Grad>(
917 std::make_shared<GradTransformationGuard>())
918 .release());
919 auto format_trans = std::make_shared<FormatTransformation>();
920 MGB_MARK_USED_VAR(
921 transformations.register_at<Segment::Format>(format_trans).release());
922
923 static py::exception<interpreter::AsyncError> py_async_error(
924 m, "AsyncError", PyExc_RuntimeError);
925 py::register_exception_translator([](std::exception_ptr p) {
926 try {
927 if (p)
928 std::rethrow_exception(p);
929 } catch (const interpreter::AsyncError& e) {
930 pyext17::pybind11_translate_exception(e.nested_ptr());
931 if (PyErr_Occurred()) {

Callers 2

PYBIND11_MODULEFunction · 0.85
buildMethod · 0.85

Calls 15

init_backtrace_tss_keyFunction · 0.85
instFunction · 0.85
record_scopeFunction · 0.85
try_castFunction · 0.85
GetGradSlotClass · 0.85
castFunction · 0.85
GetIdClass · 0.85
strFunction · 0.85
TraceErrorClass · 0.85
CreateTensorClass · 0.85
sortFunction · 0.85

Tested by 1

buildMethod · 0.68