mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/33851 Rationale and context described in #33828. Script to reproduce the move: https://gist.github.com/suo/16cbefaaeb67ca5a7c6caffd49b7f6e9 ghstack-source-id: 99079645 Test Plan: Make sure CI passes Reviewed By: jamesr66a Differential Revision: D20133869 fbshipit-source-id: 390e9241a9c85366d9005c492ac31f10aa96488e
41 lines
910 B
C++
41 lines
910 B
C++
#include <torch/custom_class.h>
|
|
|
|
#include <atomic>
|
|
|
|
namespace torch {
|
|
namespace jit {
|
|
|
|
std::vector<c10::RegisterOperators>& registeredOps() {
|
|
static std::vector<c10::RegisterOperators> ops;
|
|
return ops;
|
|
}
|
|
|
|
std::shared_ptr<script::CompilationUnit>& classCU() {
|
|
static std::shared_ptr<script::CompilationUnit> cu =
|
|
std::make_shared<script::CompilationUnit>();
|
|
return cu;
|
|
}
|
|
|
|
bool isCustomClass(const c10::IValue& v) {
|
|
return v.isObject() && v.toObject()->type()->name() &&
|
|
getCustomClass(v.toObject()->type()->name()->qualifiedName());
|
|
}
|
|
|
|
namespace {
|
|
|
|
TypePtr realCustomClassHandler(const std::string& name) {
|
|
return classCU()->get_type(name);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int register_custom_class_handler() {
|
|
setGetCustomClassFn(realCustomClassHandler);
|
|
return 0;
|
|
};
|
|
|
|
static int ensure_custom_class_handler_registered = register_custom_class_handler();
|
|
|
|
} // namespace jit
|
|
} // namespace torch
|