[Parallel_libs-commits] [parallel-libs] r279779 - [StreamExecutor] Add Platform and PlatformManager
Jason Henline via Parallel_libs-commits
parallel_libs-commits at lists.llvm.org
Thu Aug 25 14:33:08 PDT 2016
Author: jhen
Date: Thu Aug 25 16:33:07 2016
New Revision: 279779
URL: http://llvm.org/viewvc/llvm-project?rev=279779&view=rev
Log:
[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
Added:
parallel-libs/trunk/streamexecutor/include/streamexecutor/Platform.h
parallel-libs/trunk/streamexecutor/include/streamexecutor/PlatformManager.h
parallel-libs/trunk/streamexecutor/lib/Platform.cpp
parallel-libs/trunk/streamexecutor/lib/PlatformManager.cpp
Modified:
parallel-libs/trunk/streamexecutor/lib/CMakeLists.txt
Added: parallel-libs/trunk/streamexecutor/include/streamexecutor/Platform.h
URL: http://llvm.org/viewvc/llvm-project/parallel-libs/trunk/streamexecutor/include/streamexecutor/Platform.h?rev=279779&view=auto
==============================================================================
--- parallel-libs/trunk/streamexecutor/include/streamexecutor/Platform.h (added)
+++ parallel-libs/trunk/streamexecutor/include/streamexecutor/Platform.h Thu Aug 25 16:33:07 2016
@@ -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
Added: parallel-libs/trunk/streamexecutor/include/streamexecutor/PlatformManager.h
URL: http://llvm.org/viewvc/llvm-project/parallel-libs/trunk/streamexecutor/include/streamexecutor/PlatformManager.h?rev=279779&view=auto
==============================================================================
--- parallel-libs/trunk/streamexecutor/include/streamexecutor/PlatformManager.h (added)
+++ parallel-libs/trunk/streamexecutor/include/streamexecutor/PlatformManager.h Thu Aug 25 16:33:07 2016
@@ -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
Modified: parallel-libs/trunk/streamexecutor/lib/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/parallel-libs/trunk/streamexecutor/lib/CMakeLists.txt?rev=279779&r1=279778&r2=279779&view=diff
==============================================================================
--- parallel-libs/trunk/streamexecutor/lib/CMakeLists.txt (original)
+++ parallel-libs/trunk/streamexecutor/lib/CMakeLists.txt Thu Aug 25 16:33:07 2016
@@ -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})
Added: parallel-libs/trunk/streamexecutor/lib/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/parallel-libs/trunk/streamexecutor/lib/Platform.cpp?rev=279779&view=auto
==============================================================================
--- parallel-libs/trunk/streamexecutor/lib/Platform.cpp (added)
+++ parallel-libs/trunk/streamexecutor/lib/Platform.cpp Thu Aug 25 16:33:07 2016
@@ -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
Added: parallel-libs/trunk/streamexecutor/lib/PlatformManager.cpp
URL: http://llvm.org/viewvc/llvm-project/parallel-libs/trunk/streamexecutor/lib/PlatformManager.cpp?rev=279779&view=auto
==============================================================================
--- parallel-libs/trunk/streamexecutor/lib/PlatformManager.cpp (added)
+++ parallel-libs/trunk/streamexecutor/lib/PlatformManager.cpp Thu Aug 25 16:33:07 2016
@@ -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
More information about the Parallel_libs-commits
mailing list