Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Basic CUDA platform implementation and cmake infrastructure to control whether it's used. A few important TODOs will be handled in later patches: * Log some error messages that can't easily be returned as Errors. * Cache modules and kernels to prevent reloading them if someone tries to reload a kernel that's already loaded. * Tolerate shared memory arguments for kernel launches. Reviewers: jlebar Subscribers: beanz, mgorny, jprice, jlebar, parallel_libs-commits Differential Revision: https://reviews.llvm.org/D24538 llvm-svn: 281524
- Loading branch information
Showing
13 changed files
with
596 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
parallel-libs/streamexecutor/include/streamexecutor/PlatformOptions.h.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//===-- PlatformOptions.h - Platform option macros --------------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// This contents of this file are filled in at configuration time. This file | ||
/// defines macros that represent the platform configuration state of the build, | ||
/// e.g. which platforms are enabled. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
|
||
#ifndef STREAMEXECUTOR_PLATFORMOPTIONS_H | ||
#define STREAMEXECUTOR_PLATFORMOPTIONS_H | ||
|
||
#cmakedefine STREAM_EXECUTOR_ENABLE_CUDA_PLATFORM | ||
|
||
#endif // STREAMEXECUTOR_PLATFORMOPTIONS_H |
42 changes: 42 additions & 0 deletions
42
parallel-libs/streamexecutor/include/streamexecutor/platforms/cuda/CUDAPlatform.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//===-- CUDAPlatform.h - CUDA platform subclass -----------------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// Declaration of the CUDAPlatform class. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef STREAMEXECUTOR_PLATFORMS_CUDA_CUDAPLATFORM_H | ||
#define STREAMEXECUTOR_PLATFORMS_CUDA_CUDAPLATFORM_H | ||
|
||
#include "streamexecutor/Platform.h" | ||
#include "streamexecutor/platforms/cuda/CUDAPlatformDevice.h" | ||
|
||
#include "llvm/Support/Mutex.h" | ||
|
||
#include <map> | ||
|
||
namespace streamexecutor { | ||
namespace cuda { | ||
|
||
class CUDAPlatform : public Platform { | ||
public: | ||
size_t getDeviceCount() const override; | ||
|
||
Expected<Device> getDevice(size_t DeviceIndex) override; | ||
|
||
private: | ||
llvm::sys::Mutex Mutex; | ||
std::map<size_t, CUDAPlatformDevice> PlatformDevices; | ||
}; | ||
|
||
} // namespace cuda | ||
} // namespace streamexecutor | ||
|
||
#endif // STREAMEXECUTOR_PLATFORMS_CUDA_CUDAPLATFORM_H |
93 changes: 93 additions & 0 deletions
93
parallel-libs/streamexecutor/include/streamexecutor/platforms/cuda/CUDAPlatformDevice.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
//===-- CUDAPlatformDevice.h - CUDAPlatformDevice class ---------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// Declaration of the CUDAPlatformDevice class. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef STREAMEXECUTOR_PLATFORMS_CUDA_CUDAPLATFORMDEVICE_H | ||
#define STREAMEXECUTOR_PLATFORMS_CUDA_CUDAPLATFORMDEVICE_H | ||
|
||
#include "streamexecutor/PlatformDevice.h" | ||
|
||
namespace streamexecutor { | ||
namespace cuda { | ||
|
||
Error CUresultToError(int CUResult, const llvm::Twine &Message); | ||
|
||
class CUDAPlatformDevice : public PlatformDevice { | ||
public: | ||
static Expected<CUDAPlatformDevice> create(size_t DeviceIndex); | ||
|
||
CUDAPlatformDevice(const CUDAPlatformDevice &) = delete; | ||
CUDAPlatformDevice &operator=(const CUDAPlatformDevice &) = delete; | ||
|
||
CUDAPlatformDevice(CUDAPlatformDevice &&) noexcept; | ||
CUDAPlatformDevice &operator=(CUDAPlatformDevice &&) noexcept; | ||
|
||
~CUDAPlatformDevice() override; | ||
|
||
std::string getName() const override; | ||
|
||
std::string getPlatformName() const override { return "CUDA"; } | ||
|
||
Expected<const void *> | ||
createKernel(const MultiKernelLoaderSpec &Spec) override; | ||
Error destroyKernel(const void *Handle) override; | ||
|
||
Expected<const void *> createStream() override; | ||
Error destroyStream(const void *Handle) override; | ||
|
||
Error launch(const void *PlatformStreamHandle, BlockDimensions BlockSize, | ||
GridDimensions GridSize, const void *PKernelHandle, | ||
const PackedKernelArgumentArrayBase &ArgumentArray) override; | ||
|
||
Error copyD2H(const void *PlatformStreamHandle, const void *DeviceSrcHandle, | ||
size_t SrcByteOffset, void *HostDst, size_t DstByteOffset, | ||
size_t ByteCount) override; | ||
|
||
Error copyH2D(const void *PlatformStreamHandle, const void *HostSrc, | ||
size_t SrcByteOffset, const void *DeviceDstHandle, | ||
size_t DstByteOffset, size_t ByteCount) override; | ||
|
||
Error copyD2D(const void *PlatformStreamHandle, const void *DeviceSrcHandle, | ||
size_t SrcByteOffset, const void *DeviceDstHandle, | ||
size_t DstByteOffset, size_t ByteCount) override; | ||
|
||
Error blockHostUntilDone(const void *PlatformStreamHandle) override; | ||
|
||
Expected<void *> allocateDeviceMemory(size_t ByteCount) override; | ||
Error freeDeviceMemory(const void *Handle) override; | ||
|
||
Error registerHostMemory(void *Memory, size_t ByteCount) override; | ||
Error unregisterHostMemory(const void *Memory) override; | ||
|
||
Error synchronousCopyD2H(const void *DeviceSrcHandle, size_t SrcByteOffset, | ||
void *HostDst, size_t DstByteOffset, | ||
size_t ByteCount) override; | ||
|
||
Error synchronousCopyH2D(const void *HostSrc, size_t SrcByteOffset, | ||
const void *DeviceDstHandle, size_t DstByteOffset, | ||
size_t ByteCount) override; | ||
|
||
Error synchronousCopyD2D(const void *DeviceDstHandle, size_t DstByteOffset, | ||
const void *DeviceSrcHandle, size_t SrcByteOffset, | ||
size_t ByteCount) override; | ||
|
||
private: | ||
CUDAPlatformDevice(size_t DeviceIndex) : DeviceIndex(DeviceIndex) {} | ||
|
||
int DeviceIndex; | ||
}; | ||
|
||
} // namespace cuda | ||
} // namespace streamexecutor | ||
|
||
#endif // STREAMEXECUTOR_PLATFORMS_CUDA_CUDAPLATFORMDEVICE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
if(STREAM_EXECUTOR_ENABLE_CUDA_PLATFORM) | ||
add_subdirectory(cuda) | ||
endif() |
5 changes: 5 additions & 0 deletions
5
parallel-libs/streamexecutor/lib/platforms/cuda/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
add_library( | ||
streamexecutor_cuda_platform | ||
OBJECT | ||
CUDAPlatform.cpp | ||
CUDAPlatformDevice.cpp) |
Oops, something went wrong.