Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/63183
Move registration of NnapiCompilation into it's own file, so that `nnapi_bind.cpp` (which contains the implementation of NnapiCompilation) can be moved to `aten_cpu`, while maintaining the selectiveness for registration.
`nnapi_bind.cpp` is moved to `aten_cpu` in https://github.com/pytorch/pytorch/pull/62919. See the PR for more details on why it's needed.
ghstack-source-id:
135900318
Test Plan: Nnapi unit tests: `python test/test_nnapi.py`
Reviewed By: iseeyuan
Differential Revision:
D30288708
fbshipit-source-id:
6ed5967fa6bd018075469d18e68f844d413cf265
#include <vector>
#include <ATen/ATen.h>
-
#include <ATen/nnapi/nnapi_bind.h>
#include <ATen/nnapi/nnapi_wrapper.h>
#include <ATen/nnapi/nnapi_model_loader.h>
CAFFE_THROW("Bad dtype");
}
-// Set flag if running on ios
-#ifdef __APPLE__
- #include <TargetConditionals.h>
- #if TARGET_OS_IPHONE
- #define IS_IOS_NNAPI_BIND
- #endif
-#endif
-
-#ifndef IS_IOS_NNAPI_BIND
-// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
-static auto register_NnapiCompilation = [](){
- try {
- return torch::jit::class_<NnapiCompilation>("_nnapi", "Compilation")
- .def(torch::jit::init<>())
- .def("init", &NnapiCompilation::init)
- .def("run", &NnapiCompilation::run)
- ;
- } catch (std::exception& exn) {
- LOG(ERROR) << "Failed to register class nnapi.Compilation: " << exn.what();
- throw;
- }
-}();
-#else
- #undef IS_IOS_NNAPI_BIND
-#endif
-
} // namespace bind
} // namespace nnapi
} // namespace torch
--- /dev/null
+#include <ATen/nnapi/nnapi_bind.h>
+
+// Set flag if running on ios
+#ifdef __APPLE__
+ #include <TargetConditionals.h>
+ #if TARGET_OS_IPHONE
+ #define IS_IOS_NNAPI_BIND
+ #endif
+#endif
+
+#ifndef IS_IOS_NNAPI_BIND
+TORCH_LIBRARY(_nnapi, m) {
+ m.class_<torch::nnapi::bind::NnapiCompilation>("Compilation")
+ .def(torch::jit::init<>())
+ .def("init", &torch::nnapi::bind::NnapiCompilation::init)
+ .def("run", &torch::nnapi::bind::NnapiCompilation::run)
+ ;
+}
+#else
+ #undef IS_IOS_NNAPI_BIND
+#endif
# Files not in native, but depends on native symbols
# "aten/src/ATen/TensorIndexing.cpp",
"aten/src/ATen/TensorIterator.cpp",
+ "aten/src/ATen/nnapi/nnapi_register.cpp",
"aten/src/ATen/nnapi/nnapi_bind.cpp",
"aten/src/ATen/nnapi/nnapi_wrapper.cpp",
"aten/src/ATen/nnapi/nnapi_model_loader.cpp",