-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstream.h
38 lines (28 loc) · 880 Bytes
/
stream.h
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
#ifndef __STREAM_HANDLING_H__
#define __STREAM_HANDLING_H__
#include <cuda.h>
#include <memory>
#include <map>
// How should streams be shared?
enum StreamSharingMode
{
perTransfer, // create a stream for every transfer
perDevice, // create a stream per device
singleStream // everyone use a single stream
};
// Make a smart pointer wrapper for cudaStream_t
typedef std::shared_ptr<cudaStream_t> StreamPtr;
// Helper class for simplifying stream sharing
class StreamManager
{
public:
// Create a StreamManager instance
explicit StreamManager(StreamSharingMode streamMode);
// Retrieve stream for device
// This method respects the stream sharing mode set in the ctor
StreamPtr retrieveStream(int device);
private:
StreamSharingMode mode;
std::map<int, StreamPtr> streams;
};
#endif