pytorch/torch/csrc/lazy/backend/backend_interface.cpp
Bin Bao 0bbe21b172 [LT] Upstream more util functions (#69098)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/69098

Add the following utils: helpers, ir_dump_util, and
tensor_util. Some of the util functions may be better organized by
grouping into different files, but we can leave that for later.

Test Plan: Imported from OSS

Reviewed By: alanwaketan

Differential Revision: D32758480

Pulled By: desertfire

fbshipit-source-id: 2a0707879f0c49573380b4c8227a3c916c99bf9a
2021-12-04 08:42:35 -08:00

44 lines
1.2 KiB
C++

#include <torch/csrc/lazy/backend/backend_interface.h>
namespace torch {
namespace lazy {
namespace {
std::atomic<const BackendImplInterface*> backend_impl_registry;
} // namespace
const BackendImplInterface* getBackend() {
auto* interface = backend_impl_registry.load();
TORCH_CHECK(interface, "Lazy tensor backend not registered.");
return interface;
}
BackendRegistrar::BackendRegistrar(
const BackendImplInterface* backend_impl_interface) {
backend_impl_registry.store(backend_impl_interface);
}
at::Tensor MakeTensorFromComputationData(
const BackendDataPtr data,
c10::optional<at::ScalarType> logical_scalar_type) {
return getBackend()->MakeTensorFromComputationData(data, logical_scalar_type);
}
std::unique_ptr<LoweringContext> LoweringContext::Create(
const std::string& name,
BackendDevice device,
c10::ArrayRef<Node*> post_order,
Util::EmissionMap emit_status) {
return getBackend()->CreateLoweringContext(
name, device, post_order, emit_status);
}
std::unique_ptr<LoweringContext> LoweringContext::Create(
const std::string& name,
BackendDevice device) {
return getBackend()->CreateLoweringContext(name, device);
}
} // namespace lazy
} // namespace torch