mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
This reverts commit bfebf254dd92f3ed35154597166e7e71fb04f31b. Differential Revision: [D39104562](https://our.internmc.facebook.com/intern/diff/D39104562) Pull Request resolved: https://github.com/pytorch/pytorch/pull/84207 Approved by: https://github.com/robieta
128 lines
4.0 KiB
C++
128 lines
4.0 KiB
C++
#include <c10/core/SymIntArrayRef.h>
|
|
#include <c10/core/TensorImpl.h>
|
|
#include <c10/core/impl/PyInterpreter.h>
|
|
|
|
namespace c10 {
|
|
namespace impl {
|
|
|
|
template <typename... Ts>
|
|
static void noop_trace_gpu_fn(const PyInterpreter*, Ts...) {
|
|
TORCH_INTERNAL_ASSERT(
|
|
0,
|
|
"attempted to call a GPU trace function after corresponding interpreter died");
|
|
}
|
|
|
|
void GPUTraceFunctionWrapper::disarm() {
|
|
event_creation_fn_ = &noop_trace_gpu_fn;
|
|
event_deletion_fn_ = &noop_trace_gpu_fn;
|
|
event_record_fn_ = &noop_trace_gpu_fn;
|
|
event_wait_fn_ = &noop_trace_gpu_fn;
|
|
memory_allocation_fn_ = &noop_trace_gpu_fn;
|
|
memory_deallocation_fn_ = &noop_trace_gpu_fn;
|
|
stream_creation_fn_ = &noop_trace_gpu_fn;
|
|
}
|
|
|
|
static std::string noop_name_fn(const PyInterpreter*) {
|
|
return "<unloaded interpreter>";
|
|
}
|
|
|
|
static void noop_decref_fn(const PyInterpreter*, PyObject*, bool) {
|
|
// no-op
|
|
}
|
|
|
|
static c10::intrusive_ptr<TensorImpl> noop_detach_fn(
|
|
const PyInterpreter*,
|
|
const TensorImpl*) {
|
|
TORCH_INTERNAL_ASSERT(
|
|
0,
|
|
"attempted to detach (shallow_copy_and_detach) Tensor with nontrivial PyObject after corresponding interpreter died");
|
|
}
|
|
|
|
static void noop_dispatch_fn(
|
|
const PyInterpreter*,
|
|
const c10::OperatorHandle& op,
|
|
torch::jit::Stack* stack) {
|
|
TORCH_INTERNAL_ASSERT(
|
|
0,
|
|
"attempted to dispatch (__torch_dispatch__) an operator on Tensor with nontrivial PyObject after corresponding interpreter died");
|
|
}
|
|
|
|
static bool noop_is_contiguous_fn(const PyInterpreter*, const TensorImpl*) {
|
|
TORCH_INTERNAL_ASSERT(
|
|
0,
|
|
"attempted to call `is_contiguous` on Tensor with nontrivial PyObject after corresponding interpreter died");
|
|
}
|
|
|
|
static c10::Device noop_device_fn(const PyInterpreter*, const TensorImpl*) {
|
|
TORCH_INTERNAL_ASSERT(
|
|
0,
|
|
"attempted to call `device` on Tensor with nontrivial PyObject after corresponding interpreter died");
|
|
}
|
|
|
|
static int64_t noop_dim_fn(const PyInterpreter*, const TensorImpl*) {
|
|
TORCH_INTERNAL_ASSERT(
|
|
0,
|
|
"attempted to call `dim` on Tensor with nontrivial PyObject after corresponding interpreter died");
|
|
}
|
|
|
|
static c10::IntArrayRef noop_strides_fn(
|
|
const PyInterpreter*,
|
|
const TensorImpl*) {
|
|
TORCH_INTERNAL_ASSERT(
|
|
0,
|
|
"attempted to call `strides` on Tensor with nontrivial PyObject after corresponding interpreter died");
|
|
}
|
|
|
|
static c10::IntArrayRef noop_sizes_fn(const PyInterpreter*, const TensorImpl*) {
|
|
TORCH_INTERNAL_ASSERT(
|
|
0,
|
|
"attempted to call `sizes` on Tensor with nontrivial PyObject after corresponding interpreter died");
|
|
}
|
|
|
|
static c10::SymIntArrayRef noop_sym_sizes_fn(
|
|
const PyInterpreter*,
|
|
const TensorImpl*) {
|
|
TORCH_INTERNAL_ASSERT(
|
|
0,
|
|
"attempted to call `sym_sizes` on Tensor with nontrivial PyObject after corresponding interpreter died");
|
|
}
|
|
|
|
static c10::Layout noop_layout_fn(const PyInterpreter*, const TensorImpl*) {
|
|
TORCH_INTERNAL_ASSERT(
|
|
0,
|
|
"attempted to call `layout` on Tensor with nontrivial PyObject after corresponding interpreter died");
|
|
}
|
|
|
|
static c10::SymIntArrayRef noop_sym_strides_fn(
|
|
const PyInterpreter*,
|
|
const TensorImpl*) {
|
|
TORCH_INTERNAL_ASSERT(
|
|
0,
|
|
"attempted to call `sym_strides` on Tensor with nontrivial PyObject after corresponding interpreter died");
|
|
}
|
|
|
|
void PyInterpreter::disarm() noexcept {
|
|
name_fn_ = &noop_name_fn;
|
|
decref_fn_ = &noop_decref_fn;
|
|
detach_fn_ = &noop_detach_fn;
|
|
dispatch_fn_ = &noop_dispatch_fn;
|
|
is_contiguous_fn_ = &noop_is_contiguous_fn;
|
|
device_fn_ = &noop_device_fn;
|
|
dim_fn_ = &noop_dim_fn;
|
|
strides_fn_ = &noop_strides_fn;
|
|
sizes_fn_ = &noop_sizes_fn;
|
|
sym_sizes_fn_ = &noop_sym_sizes_fn;
|
|
layout_fn_ = &noop_layout_fn;
|
|
trace_gpu_functions.disarm();
|
|
sym_strides_fn_ = &noop_sym_strides_fn;
|
|
}
|
|
|
|
// Defined out-of-line because it needs access to the definition of TensorImpl.
|
|
__ubsan_ignore_function__ c10::intrusive_ptr<TensorImpl> PyInterpreter::detach(
|
|
const TensorImpl* self) const {
|
|
return (*detach_fn_)(this, self);
|
|
}
|
|
|
|
} // namespace impl
|
|
} // namespace c10
|