summaryrefslogtreecommitdiff
path: root/parallel-libs/streamexecutor/include/streamexecutor/PlatformManager.h
blob: 7d0de12528d5c470c2d7bbc0fb08ec2141725cb0 (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
//===-- PlatformManager.h - The PlatformManager class -----------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// PlatformManager is the entry point into the StreamExecutor API. A user
/// begins be calling PlatformManager::getPlatformByName("cuda") where "cuda"
/// can be replaced by any supported platform name. This gives the user a
/// Platform object that can be used to create Device objects for that platform,
/// etc.
///
//===----------------------------------------------------------------------===//

#ifndef STREAMEXECUTOR_PLATFORMMANAGER_H
#define STREAMEXECUTOR_PLATFORMMANAGER_H

#include <map>

#include "streamexecutor/Error.h"
#include "streamexecutor/Platform.h"

namespace streamexecutor {

/// A singleton that holds a reference to a Platform object for each
/// supported StreamExecutor platform.
class PlatformManager {
public:
  /// Gets a reference to the Platform with the given name.
  ///
  /// The name parameter is not case-sensitive, so the following arguments are
  /// all equivalent: "cuda", "CUDA", "Cuda", "cUdA".
  ///
  /// Returns an error if no platform is present for the name.
  ///
  /// Ownership of the platform is NOT transferred to the caller.
  static Expected<Platform *> getPlatformByName(llvm::StringRef Name);

private:
  PlatformManager();
  PlatformManager(const PlatformManager &) = delete;
  PlatformManager operator=(const PlatformManager &) = delete;

  std::map<std::string, std::unique_ptr<Platform>> PlatformsByName;
};

} // namespace streamexecutor

#endif // STREAMEXECUTOR_PLATFORMMANAGER_H