blob: bd393a6efb16a30ab72a5dd7c2106cafefeae9b0 (
plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// Contains device-level options that can be specified at a platform level.
// Example usage:
// auto device_options = DeviceOptions::Default();
#ifndef TENSORFLOW_STREAM_EXECUTOR_DEVICE_OPTIONS_H_
#define TENSORFLOW_STREAM_EXECUTOR_DEVICE_OPTIONS_H_
#include "tensorflow/stream_executor/platform/port.h"
#include "tensorflow/stream_executor/platform/logging.h"
namespace perftools {
namespace gputools {
// Indicates a set of options for a device's usage, which generally must be
// provided at StreamExecutor device-initialization time.
//
// These are intended to be useful-but-not-mandatorily-supported options for
// using devices on the underlying platform. Presently, if the option requested
// is not available on the target platform, a warning will be emitted.
struct DeviceOptions {
public:
// When it is observed that more memory has to be allocated for thread stacks,
// this flag prevents it from ever being deallocated. Potentially saves
// thrashing the thread stack memory allocation, but at the potential cost of
// some memory space.
static const unsigned kDoNotReclaimStackAllocation = 0x1;
// The following options refer to synchronization options when
// using SynchronizeStream or SynchronizeContext.
// Synchronize with spinlocks.
static const unsigned kScheduleSpin = 0x02;
// Synchronize with spinlocks that also call CPU yield instructions.
static const unsigned kScheduleYield = 0x04;
// Synchronize with a "synchronization primitive" (e.g. mutex).
static const unsigned kScheduleBlockingSync = 0x08;
static const unsigned kMask = 0xf; // Mask of all available flags.
// Constructs an or-d together set of device options.
explicit DeviceOptions(unsigned flags) : flags_(flags) {
CHECK((flags & kMask) == flags);
}
// Factory for the default set of device options.
static DeviceOptions Default() { return DeviceOptions(0); }
unsigned flags() const { return flags_; }
bool operator==(const DeviceOptions& other) const {
return flags_ == other.flags_;
}
bool operator!=(const DeviceOptions& other) const {
return !(*this == other);
}
string ToString() {
return flags_ == 0 ? "none" : "kDoNotReclaimStackAllocation";
}
private:
unsigned flags_;
};
} // namespace gputools
} // namespace perftools
#endif // TENSORFLOW_STREAM_EXECUTOR_DEVICE_OPTIONS_H_
|