interpreter.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Copyright 2019-2020 Canaan Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #pragma once
  16. #include "k210_sim_types.h"
  17. #include <runtime/interpreter.h>
  18. namespace nncase
  19. {
  20. namespace runtime
  21. {
  22. namespace k210
  23. {
  24. struct k210_interpreter_context
  25. {
  26. interpreter_base *interpreter;
  27. interpreter_step_t step;
  28. };
  29. class interpreter : public interpreter_base
  30. {
  31. public:
  32. using interpreter_base::memory_at;
  33. interpreter();
  34. #if !NNCASE_TARGET_K210_SIMULATOR
  35. dmac_channel_number_t dma_ch() const noexcept { return dma_ch_; }
  36. void dma_ch(dmac_channel_number_t dma_ch) noexcept { dma_ch_ = dma_ch; }
  37. k210_interpreter_context &context() noexcept { return context_; }
  38. clock_t::time_point get_now() const noexcept override;
  39. #endif
  40. protected:
  41. xtl::span<uint8_t> memory_at(const memory_range &range) const noexcept override;
  42. private:
  43. #if NNCASE_TARGET_K210_SIMULATOR
  44. std::unique_ptr<uint8_t[]> kpu_mem_;
  45. #else
  46. dmac_channel_number_t dma_ch_;
  47. k210_interpreter_context context_;
  48. #endif
  49. };
  50. }
  51. }
  52. }