CIRCT 20.0.0git
Loading...
Searching...
No Matches
Engines.h
Go to the documentation of this file.
1//===- Engines.h - Implement port communication -----------------*- 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//
13//===----------------------------------------------------------------------===//
14//
15// Engines (as in DMA engine) implement the actual communication between the
16// host and the accelerator. They are low level of the ESI runtime API and are
17// not intended to be used directly by users.
18//
19// They are called "engines" rather than "DMA engines" since communication need
20// not be implemented via DMA.
21//
22//===----------------------------------------------------------------------===//
23
24// NOLINTNEXTLINE(llvm-header-guard)
25#ifndef ESI_ENGINGES_H
26#define ESI_ENGINGES_H
27
28#include "esi/Common.h"
29#include "esi/Ports.h"
30#include "esi/Services.h"
31#include "esi/Utils.h"
32
33#include <cassert>
34#include <future>
35
36namespace esi {
37
38/// Engines implement the actual channel communication between the host and the
39/// accelerator. Engines can support multiple channels. They are low level of
40/// the ESI runtime API and are not intended to be used directly by users.
41class Engine {
42public:
43 virtual ~Engine() = default;
44 /// Start the engine, if applicable.
45 virtual void connect(){};
46 /// Stop the engine, if applicable.
47 virtual void disconnect(){};
48 /// Get a port for a channel, from the cache if it exists or create it. An
49 /// engine may override this method if different behavior is desired.
50 virtual ChannelPort &requestPort(AppIDPath idPath,
51 const std::string &channelName,
52 BundleType::Direction dir, const Type *type);
53
54protected:
55 /// Each engine needs to know how to create a ports. This method is called if
56 /// a port doesn't exist in the engine cache.
57 virtual std::unique_ptr<ChannelPort>
58 createPort(AppIDPath idPath, const std::string &channelName,
59 BundleType::Direction dir, const Type *type) = 0;
60
61private:
62 std::map<std::pair<AppIDPath, std::string>, std::unique_ptr<ChannelPort>>
64};
65
66/// Since engines can support multiple channels BUT not necessarily all of the
67/// channels in a bundle, a mapping from bundle channels to engines is needed.
70
71public:
72 /// Request ports for all the channels in a bundle. If the engine doesn't
73 /// exist for a particular channel, skip said channel.
74 PortMap requestPorts(const AppIDPath &idPath,
75 const BundleType *bundleType) const;
76
77private:
78 /// Set a particlar engine for a particular channel. Should only be called by
79 /// AcceleratorConnection while registering engines.
80 void setEngine(const std::string &channelName, Engine *engine);
81 std::map<std::string, Engine *> bundleEngineMap;
82};
83
84namespace registry {
85
86/// Create an engine by name. This is the primary way to create engines for
87/// "normal" backends.
88std::unique_ptr<Engine> createEngine(AcceleratorConnection &conn,
89 const std::string &dmaEngineName,
90 AppIDPath idPath,
91 const ServiceImplDetails &details,
92 const HWClientDetails &clients);
93
94namespace internal {
95
96/// Engines can register themselves for pluggable functionality.
97using EngineCreate = std::function<std::unique_ptr<Engine>(
98 AcceleratorConnection &conn, AppIDPath idPath,
99 const ServiceImplDetails &details, const HWClientDetails &clients)>;
100void registerEngine(const std::string &name, EngineCreate create);
101
102/// Helper struct to register engines.
103template <typename TEngine>
105 RegisterEngine(const char *name) { registerEngine(name, &TEngine::create); }
106};
107
108#define REGISTER_ENGINE(Name, TEngine) \
109 static ::esi::registry::internal::RegisterEngine<TEngine> \
110 __register_engine____LINE__(Name)
111
112} // namespace internal
113} // namespace registry
114
115} // namespace esi
116
117#endif // ESI_PORTS_H
Abstract class representing a connection to an accelerator.
Definition Accelerator.h:79
Since engines can support multiple channels BUT not necessarily all of the channels in a bundle,...
Definition Engines.h:68
PortMap requestPorts(const AppIDPath &idPath, const BundleType *bundleType) const
Request ports for all the channels in a bundle.
Definition Engines.cpp:62
std::map< std::string, Engine * > bundleEngineMap
Definition Engines.h:81
void setEngine(const std::string &channelName, Engine *engine)
Set a particlar engine for a particular channel.
Definition Engines.cpp:76
Bundles represent a collection of channels.
Definition Types.h:44
Unidirectional channels are the basic communication primitive between the host and accelerator.
Definition Ports.h:36
Engines implement the actual channel communication between the host and the accelerator.
Definition Engines.h:41
virtual void connect()
Start the engine, if applicable.
Definition Engines.h:45
virtual ChannelPort & requestPort(AppIDPath idPath, const std::string &channelName, BundleType::Direction dir, const Type *type)
Get a port for a channel, from the cache if it exists or create it.
Definition Engines.cpp:49
virtual std::unique_ptr< ChannelPort > createPort(AppIDPath idPath, const std::string &channelName, BundleType::Direction dir, const Type *type)=0
Each engine needs to know how to create a ports.
virtual ~Engine()=default
virtual void disconnect()
Stop the engine, if applicable.
Definition Engines.h:47
std::map< std::pair< AppIDPath, std::string >, std::unique_ptr< ChannelPort > > ownedPorts
Definition Engines.h:63
Root class of the ESI type system.
Definition Types.h:27
std::function< std::unique_ptr< Engine >(AcceleratorConnection &conn, AppIDPath idPath, const ServiceImplDetails &details, const HWClientDetails &clients)> EngineCreate
Engines can register themselves for pluggable functionality.
Definition Engines.h:99
void registerEngine(const std::string &name, EngineCreate create)
Definition Engines.cpp:111
std::unique_ptr< Engine > createEngine(AcceleratorConnection &conn, const std::string &dmaEngineName, AppIDPath idPath, const ServiceImplDetails &details, const HWClientDetails &clients)
Create an engine by name.
Definition Engines.cpp:100
Definition esi.py:1
std::map< std::string, std::any > ServiceImplDetails
Definition Common.h:98
std::map< std::string, ChannelPort & > PortMap
Definition Ports.h:29
std::vector< HWClientDetail > HWClientDetails
Definition Common.h:97
Helper struct to register engines.
Definition Engines.h:104