aboutsummaryrefslogtreecommitdiff
path: root/parallel-libs
diff options
context:
space:
mode:
authorJason Henline <jhen@google.com>2016-08-25 21:33:07 +0000
committerJason Henline <jhen@google.com>2016-08-25 21:33:07 +0000
commit20cf1eb16106bdb0b8787e55df9dfb63ae86464e (patch)
treee412f5211f805c4603274d068675c95ec3c9d86b /parallel-libs
parent3ad8b43cc279b385fa19728aa0b0cbc52694b931 (diff)
[StreamExecutor] Add Platform and PlatformManager
Summary: Abstractions for a StreamExecutor platform Reviewers: jlebar Subscribers: jprice, parallel_libs-commits Differential Revision: https://reviews.llvm.org/D23857 llvm-svn: 279779
Diffstat (limited to 'parallel-libs')
-rw-r--r--parallel-libs/streamexecutor/include/streamexecutor/Platform.h42
-rw-r--r--parallel-libs/streamexecutor/include/streamexecutor/PlatformManager.h53
-rw-r--r--parallel-libs/streamexecutor/lib/CMakeLists.txt2
-rw-r--r--parallel-libs/streamexecutor/lib/Platform.cpp21
-rw-r--r--parallel-libs/streamexecutor/lib/PlatformManager.cpp36
5 files changed, 154 insertions, 0 deletions
diff --git a/parallel-libs/streamexecutor/include/streamexecutor/Platform.h b/parallel-libs/streamexecutor/include/streamexecutor/Platform.h
new file mode 100644
index 000000000000..674a40c0ab19
--- /dev/null
+++ b/parallel-libs/streamexecutor/include/streamexecutor/Platform.h
@@ -0,0 +1,42 @@
+//===-- Platform.h - The Platform class -------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// The Platform class which represents a platform such as CUDA or OpenCL.
+///
+/// This is an abstract base class that will be overridden by each specific
+/// platform.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef STREAMEXECUTOR_PLATFORM_H
+#define STREAMEXECUTOR_PLATFORM_H
+
+#include "streamexecutor/Utils/Error.h"
+
+namespace streamexecutor {
+
+class Device;
+
+class Platform {
+public:
+ virtual ~Platform();
+
+ /// Gets the number of devices available for this platform.
+ virtual size_t getDeviceCount() const = 0;
+
+ /// Gets a pointer to a Device with the given index for this platform.
+ ///
+ /// Ownership of the Device instance is NOT transferred to the caller.
+ virtual Expected<Device *> getDevice(size_t DeviceIndex) = 0;
+};
+
+} // namespace streamexecutor
+
+#endif // STREAMEXECUTOR_PLATFORM_H
diff --git a/parallel-libs/streamexecutor/include/streamexecutor/PlatformManager.h b/parallel-libs/streamexecutor/include/streamexecutor/PlatformManager.h
new file mode 100644
index 000000000000..c8f68fc1741d
--- /dev/null
+++ b/parallel-libs/streamexecutor/include/streamexecutor/PlatformManager.h
@@ -0,0 +1,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/Platform.h"
+#include "streamexecutor/Utils/Error.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
diff --git a/parallel-libs/streamexecutor/lib/CMakeLists.txt b/parallel-libs/streamexecutor/lib/CMakeLists.txt
index cf7baf9c7e29..f33e3463b157 100644
--- a/parallel-libs/streamexecutor/lib/CMakeLists.txt
+++ b/parallel-libs/streamexecutor/lib/CMakeLists.txt
@@ -10,7 +10,9 @@ add_library(
Kernel.cpp
KernelSpec.cpp
PackedKernelArgumentArray.cpp
+ Platform.cpp
PlatformInterfaces.cpp
+ PlatformManager.cpp
Stream.cpp)
target_link_libraries(streamexecutor ${llvm_libs})
diff --git a/parallel-libs/streamexecutor/lib/Platform.cpp b/parallel-libs/streamexecutor/lib/Platform.cpp
new file mode 100644
index 000000000000..4250468a0224
--- /dev/null
+++ b/parallel-libs/streamexecutor/lib/Platform.cpp
@@ -0,0 +1,21 @@
+//===-- Platform.cpp - Platform implementation ----------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of Platform class internals.
+///
+//===----------------------------------------------------------------------===//
+
+#include "streamexecutor/Platform.h"
+
+namespace streamexecutor {
+
+Platform::~Platform() = default;
+
+} // namespace streamexecutor
diff --git a/parallel-libs/streamexecutor/lib/PlatformManager.cpp b/parallel-libs/streamexecutor/lib/PlatformManager.cpp
new file mode 100644
index 000000000000..9cae5b1ea4bb
--- /dev/null
+++ b/parallel-libs/streamexecutor/lib/PlatformManager.cpp
@@ -0,0 +1,36 @@
+//===-- PlatformManager.cpp - PlatformManager implementation --------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of PlatformManager class internals.
+///
+//===----------------------------------------------------------------------===//
+
+#include "streamexecutor/PlatformManager.h"
+
+namespace streamexecutor {
+
+PlatformManager::PlatformManager() {
+ // TODO(jhen): Register known platforms by name.
+ // We have a couple of options here:
+ // * Use build-system flags to set preprocessor macros that select the
+ // appropriate code to include here.
+ // * Use static initialization tricks to have platform libraries register
+ // themselves when they are loaded.
+}
+
+Expected<Platform *> PlatformManager::getPlatformByName(llvm::StringRef Name) {
+ static PlatformManager Instance;
+ auto Iterator = Instance.PlatformsByName.find(Name.lower());
+ if (Iterator != Instance.PlatformsByName.end())
+ return Iterator->second.get();
+ return make_error("no available platform with name " + Name);
+}
+
+} // namespace streamexecutor