-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[StreamExecutor] Add basic Stream operations
Summary: Add the Stream class and a few of the operations it supports. Reviewers: jlebar, tra Subscribers: jprice, parallel_libs-commits Differential Revision: https://reviews.llvm.org/D23333 llvm-svn: 278829
- Loading branch information
Showing
16 changed files
with
732 additions
and
49 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
29 changes: 0 additions & 29 deletions
29
parallel-libs/streamexecutor/include/streamexecutor/Interfaces.h
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
parallel-libs/streamexecutor/include/streamexecutor/LaunchDimensions.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,47 @@ | ||
//===-- LaunchDimensions.h - Kernel block and grid sizes --------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// Structures to hold sizes for blocks and grids which are used as parameters | ||
/// for kernel launches. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef STREAMEXECUTOR_LAUNCHDIMENSIONS_H | ||
#define STREAMEXECUTOR_LAUNCHDIMENSIONS_H | ||
|
||
namespace streamexecutor { | ||
|
||
/// The dimensions of a device block of execution. | ||
/// | ||
/// A block is made up of an array of X by Y by Z threads. | ||
struct BlockDimensions { | ||
BlockDimensions(unsigned X = 1, unsigned Y = 1, unsigned Z = 1) | ||
: X(X), Y(Y), Z(Z) {} | ||
|
||
unsigned X; | ||
unsigned Y; | ||
unsigned Z; | ||
}; | ||
|
||
/// The dimensions of a device grid of execution. | ||
/// | ||
/// A grid is made up of an array of X by Y by Z blocks. | ||
struct GridDimensions { | ||
GridDimensions(unsigned X = 1, unsigned Y = 1, unsigned Z = 1) | ||
: X(X), Y(Y), Z(Z) {} | ||
|
||
unsigned X; | ||
unsigned Y; | ||
unsigned Z; | ||
}; | ||
|
||
} // namespace streamexecutor | ||
|
||
#endif // STREAMEXECUTOR_LAUNCHDIMENSIONS_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
108 changes: 108 additions & 0 deletions
108
parallel-libs/streamexecutor/include/streamexecutor/PlatformInterfaces.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,108 @@ | ||
//===-- PlatformInterfaces.h - Interfaces to platform impls -----*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// Interfaces to platform-specific implementations. | ||
/// | ||
/// The general pattern is that the functions in these interfaces take raw | ||
/// handle types as parameters. This means that these types and functions are | ||
/// not intended for public use. Instead, corresponding methods in public types | ||
/// like Stream, StreamExecutor, and Kernel use C++ templates to create | ||
/// type-safe public interfaces. Those public functions do the type-unsafe work | ||
/// of extracting raw handles from their arguments and forwarding those handles | ||
/// to the methods defined in this file in the proper format. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef STREAMEXECUTOR_PLATFORMINTERFACES_H | ||
#define STREAMEXECUTOR_PLATFORMINTERFACES_H | ||
|
||
#include "streamexecutor/DeviceMemory.h" | ||
#include "streamexecutor/Kernel.h" | ||
#include "streamexecutor/LaunchDimensions.h" | ||
#include "streamexecutor/PackedKernelArgumentArray.h" | ||
#include "streamexecutor/Utils/Error.h" | ||
|
||
namespace streamexecutor { | ||
|
||
class PlatformStreamExecutor; | ||
|
||
/// Methods supported by device kernel function objects on all platforms. | ||
class KernelInterface { | ||
// TODO(jhen): Add methods. | ||
}; | ||
|
||
/// Platform-specific stream handle. | ||
class PlatformStreamHandle { | ||
public: | ||
explicit PlatformStreamHandle(PlatformStreamExecutor *Executor) | ||
: Executor(Executor) {} | ||
|
||
virtual ~PlatformStreamHandle(); | ||
|
||
PlatformStreamExecutor *getExecutor() { return Executor; } | ||
|
||
private: | ||
PlatformStreamExecutor *Executor; | ||
}; | ||
|
||
/// Raw executor methods that must be implemented by each platform. | ||
/// | ||
/// This class defines the platform interface that supports executing work on a | ||
/// device. | ||
/// | ||
/// The public StreamExecutor and Stream classes have the type-safe versions of | ||
/// the functions in this interface. | ||
class PlatformStreamExecutor { | ||
public: | ||
virtual ~PlatformStreamExecutor(); | ||
|
||
virtual std::string getName() const = 0; | ||
|
||
/// Creates a platform-specific stream. | ||
virtual Expected<std::unique_ptr<PlatformStreamHandle>> createStream() = 0; | ||
|
||
/// Launches a kernel on the given stream. | ||
virtual Error launch(PlatformStreamHandle *S, BlockDimensions BlockSize, | ||
GridDimensions GridSize, const KernelBase &Kernel, | ||
const PackedKernelArgumentArrayBase &ArgumentArray) { | ||
return make_error("launch not implemented for platform " + getName()); | ||
} | ||
|
||
/// Copies data from the device to the host. | ||
virtual Error memcpyD2H(PlatformStreamHandle *S, | ||
const GlobalDeviceMemoryBase &DeviceSrc, | ||
void *HostDst, size_t ByteCount) { | ||
return make_error("memcpyD2H not implemented for platform " + getName()); | ||
} | ||
|
||
/// Copies data from the host to the device. | ||
virtual Error memcpyH2D(PlatformStreamHandle *S, const void *HostSrc, | ||
GlobalDeviceMemoryBase *DeviceDst, size_t ByteCount) { | ||
return make_error("memcpyH2D not implemented for platform " + getName()); | ||
} | ||
|
||
/// Copies data from one device location to another. | ||
virtual Error memcpyD2D(PlatformStreamHandle *S, | ||
const GlobalDeviceMemoryBase &DeviceSrc, | ||
GlobalDeviceMemoryBase *DeviceDst, size_t ByteCount) { | ||
return make_error("memcpyD2D not implemented for platform " + getName()); | ||
} | ||
|
||
/// Blocks the host until the given stream completes all the work enqueued up | ||
/// to the point this function is called. | ||
virtual Error blockHostUntilDone(PlatformStreamHandle *S) { | ||
return make_error("blockHostUntilDone not implemented for platform " + | ||
getName()); | ||
} | ||
}; | ||
|
||
} // namespace streamexecutor | ||
|
||
#endif // STREAMEXECUTOR_PLATFORMINTERFACES_H |
Oops, something went wrong.