mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Part of implementing CacheEntry invalidation to fix https://github.com/pytorch/pytorch/issues/112090. Changes: - Move CacheEntry and ExtraState to C++ - Use pybind to control reference counting - Use std::list instead of manually implementing a linked list Pull Request resolved: https://github.com/pytorch/pytorch/pull/118438 Approved by: https://github.com/jansel
31 lines
793 B
C++
31 lines
793 B
C++
#include <torch/csrc/dynamo/cache_entry.h>
|
|
|
|
#include <torch/csrc/dynamo/debug_macros.h>
|
|
#include <torch/csrc/dynamo/extra_state.h>
|
|
|
|
CacheEntry::CacheEntry(const py::handle& guarded_code) {
|
|
this->check_fn = guarded_code.attr("check_fn");
|
|
this->code = guarded_code.attr("code");
|
|
}
|
|
|
|
py::object CacheEntry::next() {
|
|
NULL_CHECK(this->_owner);
|
|
auto it = this->_owner_loc;
|
|
++it;
|
|
if (it == this->_owner->cache_entry_list.end()) {
|
|
return py::none();
|
|
}
|
|
return py::cast(*it, py::return_value_policy::reference);
|
|
}
|
|
|
|
PyCodeObject* CacheEntry_get_code(CacheEntry* e) {
|
|
return (PyCodeObject*)e->code.ptr();
|
|
}
|
|
|
|
PyObject* CacheEntry_to_obj(CacheEntry* e) {
|
|
if (!e) {
|
|
return py::none().release().ptr();
|
|
}
|
|
return py::cast(e, py::return_value_policy::reference).release().ptr();
|
|
}
|