| 468 | { |
| 469 | public: |
| 470 | void* reallocateOutput( |
| 471 | char const* tensorName, void* currentMemory, uint64_t size, uint64_t alignment) noexcept override |
| 472 | { |
| 473 | try |
| 474 | { |
| 475 | py::gil_scoped_acquire gil{}; |
| 476 | py::function pyFunc = utils::getOverride(static_cast<IOutputAllocator*>(this), "reallocate_output"); |
| 477 | |
| 478 | if (!pyFunc) |
| 479 | { |
| 480 | return nullptr; |
| 481 | } |
| 482 | |
| 483 | py::object ptr = pyFunc(tensorName, reinterpret_cast<size_t>(currentMemory), size, alignment); |
| 484 | try |
| 485 | { |
| 486 | return reinterpret_cast<void*>(ptr.cast<size_t>()); |
| 487 | } |
| 488 | catch (const py::cast_error& e) |
| 489 | { |
| 490 | std::cerr << "[ERROR] Return value of reallocateOutput() could not be interpreted as an int" |
| 491 | << std::endl; |
| 492 | } |
| 493 | } |
| 494 | catch (std::exception const& e) |
| 495 | { |
| 496 | std::cerr << "[ERROR] Exception caught in reallocateOutput(): " << e.what() << std::endl; |
| 497 | } |
| 498 | catch (...) |
| 499 | { |
| 500 | std::cerr << "[ERROR] Exception caught in reallocateOutput()" << std::endl; |
| 501 | return nullptr; |
| 502 | } |
| 503 | |
| 504 | return nullptr; |
| 505 | } |
| 506 | |
| 507 | void notifyShape(char const* tensorName, Dims const& dims) noexcept override |
| 508 | { |
nothing calls this directly
no test coverage detected