mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
2f154f68ea
## Job Test running on most CI jobs. ## Test binary * `test_main.cpp`: entry for gtest * `test_operator_registration.cpp`: test cases for gtest ## Helper sources * `operator_registry.h/cpp`: simple operator registry for testing purpose. * `Evalue.h`: a boxed data type that wraps ATen types, for testing purpose. * `selected_operators.yaml`: operators Executorch care about so far, we should cover all of them. ## Templates * `NativeFunctions.h`: for generating headers for native functions. (not compiled in the test, since we will be using `libtorch`) * `RegisterCodegenUnboxedKernels.cpp`: for registering boxed operators. * `Functions.h`: for declaring operator C++ APIs. Generated `Functions.h` merely wraps `ATen/Functions.h`. ## Build files * `CMakeLists.txt`: generate code to register ops. * `build.sh`: driver file, to be called by CI job. Pull Request resolved: https://github.com/pytorch/pytorch/pull/89596 Approved by: https://github.com/ezyang
46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
#include <c10/util/Exception.h>
|
|
#include <operator_registry.h>
|
|
|
|
namespace torch {
|
|
namespace executor {
|
|
|
|
OperatorRegistry& getOperatorRegistry() {
|
|
static OperatorRegistry operator_registry;
|
|
return operator_registry;
|
|
}
|
|
|
|
bool register_operators(const ArrayRef<Operator>& operators) {
|
|
return getOperatorRegistry().register_operators(operators);
|
|
}
|
|
|
|
bool OperatorRegistry::register_operators(
|
|
const ArrayRef<Operator>& operators) {
|
|
for (const auto& op : operators) {
|
|
this->operators_map_[op.name_] = op.op_;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool hasOpsFn(const char* name) {
|
|
return getOperatorRegistry().hasOpsFn(name);
|
|
}
|
|
|
|
bool OperatorRegistry::hasOpsFn(const char* name) {
|
|
auto op = this->operators_map_.find(name);
|
|
return op != this->operators_map_.end();
|
|
}
|
|
|
|
OpFunction& getOpsFn(const char* name) {
|
|
return getOperatorRegistry().getOpsFn(name);
|
|
}
|
|
|
|
OpFunction& OperatorRegistry::getOpsFn(const char* name) {
|
|
auto op = this->operators_map_.find(name);
|
|
TORCH_CHECK_MSG(op != this->operators_map_.end(), "Operator not found!");
|
|
return op->second;
|
|
}
|
|
|
|
|
|
} // namespace executor
|
|
} // namespace torch
|