-
Notifications
You must be signed in to change notification settings - Fork 1
/
AbstractAPI.h
126 lines (104 loc) · 4.68 KB
/
AbstractAPI.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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef DEVICE_ABSTRACT_API_H
#define DEVICE_ABSTRACT_API_H
#include "DataTypes.h"
#include <cstdint>
#include <cstdlib>
#include <functional>
#include <string>
#include <vector>
namespace device {
enum class Destination { Host, CurrentDevice };
enum class StreamType { Blocking, NonBlocking };
enum class ProfilingColors : uint32_t {
Black = 0x000000,
White = 0xFFFFFF,
Red = 0xFF0000,
Lime = 0x00FF00,
Blue = 0x0000FF,
Yellow = 0xFFFF00,
Cyan = 0x00FFFF,
Magenta = 0xFF00FF,
Count = 8
};
struct AbstractAPI {
virtual ~AbstractAPI() = default;
virtual void setDevice(int deviceId) = 0;
virtual int getDeviceId() = 0;
virtual int getNumDevices() = 0;
virtual size_t getLaneSize() = 0;
virtual unsigned getMaxThreadBlockSize() = 0;
virtual unsigned getMaxSharedMemSize() = 0;
virtual unsigned getGlobMemAlignment() = 0;
virtual std::string getDeviceInfoAsText(int deviceId) = 0;
virtual void syncDevice() = 0;
virtual void checkOffloading() = 0;
virtual std::string getApiName() = 0;
virtual std::string getDeviceName(int deviceId) = 0;
virtual std::string getPciAddress(int deviceId) = 0;
virtual void allocateStackMem() = 0;
virtual void *allocGlobMem(size_t size) = 0;
virtual void *allocUnifiedMem(size_t size) = 0;
virtual void *allocPinnedMem(size_t size) = 0;
virtual char *getStackMemory(size_t requestedBytes) = 0;
virtual void freeMem(void *devPtr) = 0;
virtual void freeGlobMem(void *devPtr) = 0;
virtual void freeUnifiedMem(void *devPtr) = 0;
virtual void freePinnedMem(void *devPtr) = 0;
virtual void popStackMemory() = 0;
virtual std::string getMemLeaksReport() = 0;
virtual void pinMemory(void* ptr, size_t size) = 0;
virtual void unpinMemory(void* ptr) = 0;
virtual void* devicePointer(void* ptr) = 0;
virtual void copyTo(void *dst, const void *src, size_t count) = 0;
virtual void copyFrom(void *dst, const void *src, size_t count) = 0;
virtual void copyBetween(void *dst, const void *src, size_t count) = 0;
virtual void copyToAsync(void *dst, const void *src, size_t count, void* streamPtr) = 0;
virtual void copyFromAsync(void *dst, const void *src, size_t count, void* streamPtr) = 0;
virtual void copyBetweenAsync(void *dst, const void *src, size_t count, void* streamPtr) = 0;
virtual void copy2dArrayTo(void *dst, size_t dpitch, const void *src, size_t spitch, size_t width,
size_t height) = 0;
virtual void copy2dArrayFrom(void *dst, size_t dpitch, const void *src, size_t spitch,
size_t width, size_t height) = 0;
virtual void prefetchUnifiedMemTo(Destination type, const void *devPtr, size_t count,
void *streamPtr) = 0;
virtual size_t getMaxAvailableMem() = 0;
virtual size_t getCurrentlyOccupiedMem() = 0;
virtual size_t getCurrentlyOccupiedUnifiedMem() = 0;
virtual void *getDefaultStream() = 0;
virtual void syncDefaultStreamWithHost() = 0;
virtual void *getNextCircularStream() = 0;
virtual void resetCircularStreamCounter() = 0;
virtual size_t getCircularStreamSize() = 0;
virtual void syncStreamFromCircularBufferWithHost(void *streamPtr) = 0;
virtual void syncCircularBuffersWithHost() = 0;
virtual void forkCircularStreamsFromDefault() = 0;
virtual void joinCircularStreamsToDefault() = 0;
virtual bool isCircularStreamsJoinedWithDefault() = 0;
virtual bool isCapableOfGraphCapturing() = 0;
virtual void streamBeginCapture(std::vector<void*>& streamPtrs) = 0;
virtual void streamEndCapture() = 0;
virtual DeviceGraphHandle getLastGraphHandle() = 0;
virtual void launchGraph(DeviceGraphHandle graphHandle, void* streamPtr) = 0;
virtual void* createGenericStream() = 0;
virtual void destroyGenericStream(void* streamPtr) = 0;
virtual void syncStreamWithHost(void* streamPtr) = 0;
virtual bool isStreamWorkDone(void* streamPtr) = 0;
virtual void syncStreamWithEvent(void* streamPtr, void* eventPtr) = 0;
virtual void streamHostFunction(void* streamPtr, const std::function<void()>& function) = 0;
virtual void* createEvent() = 0;
virtual void destroyEvent(void* eventPtr) = 0;
virtual void syncEventWithHost(void* eventPtr) = 0;
virtual bool isEventCompleted(void* eventPtr) = 0;
virtual void recordEventOnHost(void* eventPtr) = 0;
virtual void recordEventOnStream(void* eventPtr, void* streamPtr) = 0;
virtual bool isUnifiedMemoryDefault() = 0;
virtual void initialize() = 0;
virtual void finalize() = 0;
virtual void putProfilingMark(const std::string &name, ProfilingColors color) = 0;
virtual void popLastProfilingMark() = 0;
bool hasFinalized() { return m_isFinalized; }
protected:
bool m_isFinalized = false;
};
} // namespace device
#endif // DEVICE_ABSTRACT_API_H