CIRCT 20.0.0git
Loading...
Searching...
No Matches
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
29using namespace esi;
30using namespace esi::services;
31using namespace esi::backends::xrt;
32
33/// Parse the connection std::string and instantiate the accelerator. Connection
34/// std::string format:
35/// <xclbin>[:<device_id>]
36/// wherein <device_id> is in BDF format.
37std::unique_ptr<AcceleratorConnection>
38XrtAccelerator::connect(Context &ctxt, std::string connectionString) {
39 std::string xclbin;
40 std::string device_id;
41
42 size_t colon = connectionString.find(':');
43 if (colon == std::string::npos) {
44 xclbin = connectionString;
45 } else {
46 xclbin = connectionString.substr(0, colon);
47 device_id = connectionString.substr(colon + 1);
48 }
49
50 return make_unique<XrtAccelerator>(ctxt, xclbin, device_id);
51}
52
54 constexpr static char kernel[] = "esi_kernel";
55
56 Impl(std::string xclbin, std::string device_id) {
57 if (device_id.empty())
58 device = ::xrt::device(0);
59 else
60 device = ::xrt::device(device_id);
61
62 auto uuid = device.load_xclbin(xclbin);
63 ip = ::xrt::ip(device, uuid, kernel);
64 }
65
66 std::map<std::string, ChannelPort &> requestChannelsFor(AppIDPath,
67 const BundleType *) {
68 throw std::runtime_error("XRT does not support channel communication yet");
69 }
70
71 ::xrt::device device;
72 ::xrt::ip ip;
73};
74
75/// Construct and connect to a cosim server.
76XrtAccelerator::XrtAccelerator(Context &ctxt, std::string xclbin,
77 std::string device_id)
78 : AcceleratorConnection(ctxt) {
79 impl = make_unique<Impl>(xclbin, device_id);
80}
82
83namespace {
84class XrtMMIO : public MMIO {
85public:
86 XrtMMIO(::xrt::ip &ip) : ip(ip) {}
87
88 uint64_t read(uint32_t addr) const override {
89 auto lo = static_cast<uint64_t>(ip.read_register(addr));
90 auto hi = static_cast<uint64_t>(ip.read_register(addr + 0x4));
91 return (hi << 32) | lo;
92 }
93 void write(uint32_t addr, uint64_t data) override {
94 ip.write_register(addr, data);
95 ip.write_register(addr + 0x4, data >> 32);
96 }
97
98private:
99 ::xrt::ip &ip;
100};
101} // namespace
102
103std::map<std::string, ChannelPort &> XrtAccelerator::requestChannelsFor(
104 AppIDPath idPath, const BundleType *bundleType, const ServiceTable &) {
105 return impl->requestChannelsFor(idPath, bundleType);
106}
107
109 std::string implName,
110 const ServiceImplDetails &details,
111 const HWClientDetails &clients) {
112 if (svcType == typeid(MMIO))
113 return new XrtMMIO(impl->ip);
114 else if (svcType == typeid(SysInfo))
115 return new MMIOSysInfo(getService<MMIO>());
116 return nullptr;
117}
118
#define REGISTER_ACCELERATOR(Name, TAccelerator)
Abstract class representing a connection to an accelerator.
Definition Accelerator.h:78
virtual void disconnect()
Disconnect from the accelerator cleanly.
std::map< std::string, services::Service * > ServiceTable
Definition Accelerator.h:93
Context & ctxt
ESI accelerator context.
Bundles represent a collection of channels.
Definition Types.h:44
AcceleratorConnections, Accelerators, and Manifests must all share a context.
Definition Context.h:31
Connect to an ESI simulation.
Definition Xrt.h:31
std::map< std::string, ChannelPort & > requestChannelsFor(AppIDPath, const BundleType *, const ServiceTable &) override
Request the host side channel ports for a particular instance (identified by the AppID path).
Definition Xrt.cpp:103
XrtAccelerator(Context &, std::string xclbin, std::string kernelName)
Construct and connect to a cosim server.
Definition Xrt.cpp:76
static std::unique_ptr< AcceleratorConnection > connect(Context &, std::string connectionString)
Parse the connection std::string and instantiate the accelerator.
Definition Xrt.cpp:38
std::unique_ptr< Impl > impl
Definition Xrt.h:54
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:108
Implement the SysInfo API for a standard MMIO protocol.
Definition Services.h:180
Parent class of all APIs modeled as 'services'.
Definition Services.h:45
const std::type_info & Type
Definition Services.h:47
Information about the Accelerator system.
Definition Services.h:93
Definition esi.py:1
std::map< std::string, std::any > ServiceImplDetails
Definition Common.h:98
std::vector< HWClientDetail > HWClientDetails
Definition Common.h:97
std::map< std::string, ChannelPort & > requestChannelsFor(AppIDPath, const BundleType *)
Definition Xrt.cpp:66
Impl(std::string xclbin, std::string device_id)
Definition Xrt.cpp:56
static constexpr char kernel[]
Definition Xrt.cpp:54