fake_micro_context.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. ==============================================================================*/
  12. #ifndef TENSORFLOW_LITE_MICRO_FAKE_MICRO_CONTEXT_H_
  13. #define TENSORFLOW_LITE_MICRO_FAKE_MICRO_CONTEXT_H_
  14. #include "tensorflow/lite/micro/micro_context.h"
  15. #include "tensorflow/lite/micro/micro_graph.h"
  16. namespace tflite {
  17. // A fake of MicroContext for kernel util tests.
  18. class FakeMicroContext : public MicroContext {
  19. public:
  20. FakeMicroContext(TfLiteTensor* tensors, SimpleMemoryAllocator* allocator,
  21. MicroGraph* micro_graph);
  22. void* AllocatePersistentBuffer(size_t bytes) override;
  23. TfLiteStatus RequestScratchBufferInArena(size_t bytes,
  24. int* buffer_index) override;
  25. void* GetScratchBuffer(int buffer_index) override;
  26. TfLiteTensor* AllocateTempTfLiteTensor(int tensor_index) override;
  27. void DeallocateTempTfLiteTensor(TfLiteTensor* tensor) override;
  28. bool IsAllTempTfLiteTensorDeallocated();
  29. TfLiteEvalTensor* GetEvalTensor(int tensor_index) override;
  30. private:
  31. static constexpr int kNumScratchBuffers_ = 12;
  32. int scratch_buffer_count_ = 0;
  33. uint8_t* scratch_buffers_[kNumScratchBuffers_];
  34. TfLiteTensor* tensors_;
  35. int allocated_tensor_count_ = 0;
  36. SimpleMemoryAllocator* allocator_;
  37. TF_LITE_REMOVE_VIRTUAL_DELETE
  38. };
  39. } // namespace tflite
  40. #endif // TENSORFLOW_LITE_MICRO_FAKE_MICRO_CONTEXT_H_