From b79dcaba86aae650f718f9b974e5be34843d16ef Mon Sep 17 00:00:00 2001 From: Chen Lai Date: Tue, 5 Nov 2024 18:08:36 -0800 Subject: [PATCH] Refactor Init function arg (#6673) Summary: The actual init function takes in backend init context instead of memory allocator directly. See https://github.com/pytorch/executorch/blob/836d5561a61877507b6d5891485725996bb6b32c/runtime/backend/interface.h#L81-L84 Update the signature in the test so it's easier to add test for exposing method name in next diff Reviewed By: iseeyuan, dbort Differential Revision: D65499276 --- runtime/executor/test/backend_integration_test.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/runtime/executor/test/backend_integration_test.cpp b/runtime/executor/test/backend_integration_test.cpp index 9180d77aa35..bf9dc0033f7 100644 --- a/runtime/executor/test/backend_integration_test.cpp +++ b/runtime/executor/test/backend_integration_test.cpp @@ -55,7 +55,7 @@ class StubBackend final : public BackendInterface { using InitFn = std::function( FreeableBuffer*, ArrayRef, - MemoryAllocator*)>; + BackendInitContext&)>; using ExecuteFn = std::function; using DestroyFn = std::function; @@ -83,8 +83,7 @@ class StubBackend final : public BackendInterface { FreeableBuffer* processed, ArrayRef compile_specs) const override { if (init_fn_) { - return init_fn_.value()( - processed, compile_specs, context.get_runtime_allocator()); + return init_fn_.value()(processed, compile_specs, context); } // Return a benign value otherwise. return nullptr; @@ -351,7 +350,7 @@ TEST_P(BackendIntegrationTest, FreeingProcessedBufferSucceeds) { StubBackend::singleton().install_init( [&](FreeableBuffer* processed, ET_UNUSED ArrayRef compile_specs, - ET_UNUSED MemoryAllocator* runtime_allocator) + ET_UNUSED BackendInitContext& backend_init_context) -> Result { init_called = true; processed_data = processed->data(); @@ -395,7 +394,7 @@ TEST_P(BackendIntegrationTest, EndToEndTestWithProcessedAsHandle) { StubBackend::singleton().install_init( [&](FreeableBuffer* processed, ET_UNUSED ArrayRef compile_specs, - ET_UNUSED MemoryAllocator* runtime_allocator) + ET_UNUSED BackendInitContext& backend_init_context) -> Result { init_processed = processed; return processed; @@ -492,7 +491,7 @@ TEST_P(BackendIntegrationTest, SegmentInfoIsPassedIntoDataLoader) { StubBackend::singleton().install_init( [&](FreeableBuffer* processed, ET_UNUSED ArrayRef compile_specs, - ET_UNUSED MemoryAllocator* runtime_allocator) + ET_UNUSED BackendInitContext& backend_init_context) -> Result { processed_data = processed->data(); processed->Free(); @@ -606,7 +605,7 @@ TEST_P(DelegateDataAlignmentTest, ExpectedDataAlignment) { StubBackend::singleton().install_init( [&](FreeableBuffer* processed, ET_UNUSED ArrayRef compile_specs, - ET_UNUSED MemoryAllocator* runtime_allocator) + ET_UNUSED BackendInitContext& backend_init_context) -> Result { processed_data = processed->data(); return nullptr;