CIRCT  19.0.0git
Accelerator.cpp
Go to the documentation of this file.
1 //===- Accelerator.cpp - ESI accelerator system API -----------------------===//
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 (lib/dialect/ESI/runtime/cpp/).
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "esi/Accelerator.h"
16 
17 #include <map>
18 #include <stdexcept>
19 
20 using namespace std;
21 
22 using namespace esi;
23 using namespace esi::services;
24 
25 namespace esi {
26 
27 services::Service *AcceleratorConnection::getService(Service::Type svcType,
28  AppIDPath id,
29  std::string implName,
30  ServiceImplDetails details,
31  HWClientDetails clients) {
32  unique_ptr<Service> &cacheEntry = serviceCache[make_tuple(&svcType, id)];
33  if (cacheEntry == nullptr) {
34  Service *svc = createService(svcType, id, implName, details, clients);
35  if (!svc)
36  svc = ServiceRegistry::createService(this, svcType, id, implName, details,
37  clients);
38  if (!svc)
39  return nullptr;
40  cacheEntry = unique_ptr<Service>(svc);
41  }
42  return cacheEntry.get();
43 }
44 
45 namespace registry {
46 namespace internal {
47 
48 static map<string, BackendCreate> backendRegistry;
49 void registerBackend(string name, BackendCreate create) {
50  if (backendRegistry.count(name))
51  throw runtime_error("Backend already exists in registry");
52  backendRegistry[name] = create;
53 }
54 } // namespace internal
55 
56 unique_ptr<AcceleratorConnection> connect(Context &ctxt, string backend,
57  string connection) {
58  auto f = internal::backendRegistry.find(backend);
59  if (f == internal::backendRegistry.end())
60  throw runtime_error("Backend not found");
61  return f->second(ctxt, connection);
62 }
63 
64 } // namespace registry
65 } // namespace esi
AcceleratorConnections, Accelerators, and Manifests must all share a context.
Definition: Context.h:30
Parent class of all APIs modeled as 'services'.
Definition: Services.h:42
const std::type_info & Type
Definition: Services.h:44
static map< string, BackendCreate > backendRegistry
Definition: Accelerator.cpp:48
std::function< std::unique_ptr< AcceleratorConnection >(Context &, std::string)> BackendCreate
Backends can register themselves to be connected via a connection string.
Definition: Accelerator.h:135
void registerBackend(string name, BackendCreate create)
Definition: Accelerator.cpp:49
unique_ptr< AcceleratorConnection > connect(Context &ctxt, string backend, string connection)
Definition: Accelerator.cpp:56
Definition: esi.py:1
std::map< std::string, std::any > ServiceImplDetails
Definition: Common.h:80
std::vector< HWClientDetail > HWClientDetails
Definition: Common.h:79