low_level_device.h 3.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

/*!
 * \file low_level_device.h
 * \brief Abstract low-level micro device management
 */
#ifndef TVM_RUNTIME_MICRO_LOW_LEVEL_DEVICE_H_
#define TVM_RUNTIME_MICRO_LOW_LEVEL_DEVICE_H_

#include <memory>
28
#include <string>
29 30 31 32 33 34 35 36 37 38 39 40 41 42

#include "micro_common.h"

namespace tvm {
namespace runtime {
/*!
 * \brief virtual interface for low-level micro device management
 */
class LowLevelDevice {
 public:
  /*! \brief virtual destructor */
  virtual ~LowLevelDevice() {}

  /*!
43 44
   * \brief reads num_bytes from device memory at addr into buffer
   * \param addr on-device memory address to read from
45
   * \param buffer on-host buffer to be read into
46
   * \param num_bytes number of bytes to read
47
   */
48
  virtual void Read(DevPtr addr,
49 50 51 52
                    void* buffer,
                    size_t num_bytes) = 0;

  /*!
53 54 55 56
   * \brief writes num_bytes from buffer to device memory at addr
   * \param addr on-device memory address to write into
   * \param buffer host buffer to write from
   * \param num_bytes number of bytes to write
57
   */
58
  virtual void Write(DevPtr addr,
59 60 61 62
                     const void* buffer,
                     size_t num_bytes) = 0;

  /*!
63
   * \brief starts execution of device at func_addr
64
   * \param func_addr offset of the init stub function
65
   * \param breakpoint_addr address at which to stop function execution
66
   */
67
  virtual void Execute(DevPtr func_addr, DevPtr breakpoint_addr) = 0;
68 69 70 71 72 73 74 75 76 77 78

  /*!
   * \brief getter function for low-level device type
   * \return string containing device type
   */
  virtual const char* device_type() const = 0;
};

/*!
 * \brief create a host low-level device
 * \param num_bytes size of the memory region
79
 * \param base_addr pointer to write the host device's resulting base address into
80
 */
81
const std::shared_ptr<LowLevelDevice> HostLowLevelDeviceCreate(size_t num_bytes, void** base_addr);
82

83 84
/*!
 * \brief connect to OpenOCD and create an OpenOCD low-level device
85
 * \param addr address of the OpenOCD server to connect to
86 87
 * \param port port of the OpenOCD server to connect to
 */
88
const std::shared_ptr<LowLevelDevice> OpenOCDLowLevelDeviceCreate(const std::string& addr,
89 90
                                                                  int port);

91 92 93
}  // namespace runtime
}  // namespace tvm
#endif  // TVM_RUNTIME_MICRO_LOW_LEVEL_DEVICE_H_