CIRCT  19.0.0git
Xrt.cpp
Go to the documentation of this file.
1 //===- Xrt.cpp - ESI XRT device backend -------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // DO NOT EDIT!
10 // This file is distributed as part of an ESI package. The source for this file
11 // should always be modified within CIRCT
12 // (lib/dialect/ESI/runtime/cpp/lib/backends/Cosim.cpp).
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #include "esi/backends/Xrt.h"
17 #include "esi/Services.h"
18 
19 // XRT includes
20 #include "experimental/xrt_bo.h"
21 #include "experimental/xrt_device.h"
22 #include "experimental/xrt_ip.h"
23 #include "experimental/xrt_xclbin.h"
24 
25 #include <fstream>
26 #include <iostream>
27 #include <set>
28 
29 using namespace std;
30 
31 using namespace esi;
32 using namespace esi::services;
33 using namespace esi::backends::xrt;
34 
35 /// Parse the connection string and instantiate the accelerator. Connection
36 /// string format:
37 /// <xclbin>[:<device_id>]
38 /// wherein <device_id> is in BDF format.
39 unique_ptr<AcceleratorConnection>
40 XrtAccelerator::connect(Context &ctxt, string connectionString) {
41  string xclbin;
42  string device_id;
43 
44  size_t colon = connectionString.find(':');
45  if (colon == string::npos) {
46  xclbin = connectionString;
47  } else {
48  xclbin = connectionString.substr(0, colon);
49  device_id = connectionString.substr(colon + 1);
50  }
51 
52  return make_unique<XrtAccelerator>(ctxt, xclbin, device_id);
53 }
54 
56  constexpr static char kernel[] = "esi_kernel";
57 
58  Impl(string xclbin, string device_id) {
59  if (device_id.empty())
60  device = ::xrt::device(0);
61  else
62  device = ::xrt::device(device_id);
63 
64  auto uuid = device.load_xclbin(xclbin);
65  ip = ::xrt::ip(device, uuid, kernel);
66  }
67 
68  std::map<std::string, ChannelPort &> requestChannelsFor(AppIDPath,
69  const BundleType *) {
70  throw runtime_error("XRT does not support channel communication yet");
71  }
72 
73  ::xrt::device device;
74  ::xrt::ip ip;
75 };
76 
77 /// Construct and connect to a cosim server.
78 XrtAccelerator::XrtAccelerator(Context &ctxt, string xclbin, string device_id)
80  impl = make_unique<Impl>(xclbin, device_id);
81 }
82 
83 namespace {
84 class XrtMMIO : public MMIO {
85 public:
86  XrtMMIO(::xrt::ip &ip) : ip(ip) {}
87 
88  uint32_t read(uint32_t addr) const override { return ip.read_register(addr); }
89  void write(uint32_t addr, uint32_t data) override {
90  ip.write_register(addr, data);
91  }
92 
93 private:
94  ::xrt::ip &ip;
95 };
96 } // namespace
97 
98 map<string, ChannelPort &>
100  const BundleType *bundleType) {
101  return impl->requestChannelsFor(idPath, bundleType);
102 }
103 
105  std::string implName,
106  const ServiceImplDetails &details,
107  const HWClientDetails &clients) {
108  if (svcType == typeid(MMIO))
109  return new XrtMMIO(impl->ip);
110  else if (svcType == typeid(SysInfo))
111  return new MMIOSysInfo(getService<MMIO>());
112  return nullptr;
113 }
114 
REGISTER_ACCELERATOR("xrt", backends::xrt::XrtAccelerator)
Abstract class representing a connection to an accelerator.
Definition: Accelerator.h:75
Bundles represent a collection of channels.
Definition: Types.h:44
AcceleratorConnections, Accelerators, and Manifests must all share a context.
Definition: Context.h:30
Connect to an ESI simulation.
Definition: Xrt.h:31
std::map< std::string, ChannelPort & > requestChannelsFor(AppIDPath, const BundleType *) override
Request the host side channel ports for a particular instance (identified by the AppID path).
Definition: Xrt.cpp:99
std::unique_ptr< Impl > impl
Definition: Xrt.h:52
virtual Service * createService(Service::Type service, AppIDPath path, std::string implName, const ServiceImplDetails &details, const HWClientDetails &clients) override
Called by getServiceImpl exclusively.
Definition: Xrt.cpp:104
Implement the SysInfo API for a standard MMIO protocol.
Definition: Services.h:102
Parent class of all APIs modeled as 'services'.
Definition: Services.h:42
const std::type_info & Type
Definition: Services.h:44
Information about the Accelerator system.
Definition: Services.h:77
def connect(destination, source)
Definition: support.py:37
Definition: esi.py:1
std::map< std::string, std::any > ServiceImplDetails
Definition: Common.h:80
std::vector< HWClientDetail > HWClientDetails
Definition: Common.h:79
std::map< std::string, ChannelPort & > requestChannelsFor(AppIDPath, const BundleType *)
Definition: Xrt.cpp:68
Impl(string xclbin, string device_id)
Definition: Xrt.cpp:58