summaryrefslogtreecommitdiff
path: root/python/openvino/runtime/coredla_device/inc/mmd_wrapper.h
blob: 401445493c1009e84a2a758da7545224a849c187 (plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2020 Intel Corporation.
//
// This software and the related documents are Intel copyrighted materials,
// and your use of them is governed by the express license under which they
// were provided to you ("License"). Unless the License provides otherwise,
// you may not use, modify, copy, publish, distribute, disclose or transmit
// this software or the related documents without Intel's prior written
// permission.
//
// This software and the related documents are provided as is, with no express
// or implied warranties, other than those that are expressly stated in the
// License.

#pragma once

#include <cstdint>  //uint32_t

using interrupt_service_routine_signature = void (*)(int handle, void *data);

class MmdWrapper {
 public:
  MmdWrapper();
  // Note that ~MmdWrapper() can call std::exit(1) if aocl_mmd_close()
  // fails.  Ideally we would find some way to re-order the code so that it
  // can throw an exception (before calling the destructor) if aocl_mmd_close()
  // fails.
  ~MmdWrapper();

  // class cannot be copied
  MmdWrapper(const MmdWrapper &) = delete;
  MmdWrapper &operator=(const MmdWrapper &) = delete;

  // Register a function to run as the interrupt service routine
  void RegisterISR(interrupt_service_routine_signature func, void *data) const;

  // 32-bit handshake with each CSR
  void WriteToCsr(int instance, uint32_t addr, uint32_t data) const;
  uint32_t ReadFromCsr(int instance, uint32_t addr) const;

  // Copy data between host and device memory
  void WriteToDDR(int instance, uint64_t addr, uint64_t length, const void *data) const;
  void ReadFromDDR(int instance, uint64_t addr, uint64_t length, void *data) const;

  // If the mmd layer supports accesses to the STREAM CONTROLLER
  bool bIsStreamControllerValid(int instance) const;

  // 32-bit handshake with each Stream Controller CSR
  void WriteToStreamController(int instance, uint32_t addr, uint64_t length, const void *data) const;
  void ReadFromStreamController(int instance, uint32_t addr, uint64_t length, void *data) const;

  // Provide read-only access to board-specific constants
  int GetMaxInstances() const { return maxInstances_; }
  uint64_t GetDDRSizePerInstance() const { return ddrSizePerInstance_; }
  double GetCoreDlaClockFreq() const { return coreDlaClockFreq_; }
  double GetDDRClockFreq() const { return ddrClockFreq_; }

 private:
  int handle_;
  int maxInstances_;
  uint64_t ddrSizePerInstance_;
  double coreDlaClockFreq_;
  double ddrClockFreq_;
};