-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathDevice.h
More file actions
130 lines (100 loc) · 3.12 KB
/
Device.h
File metadata and controls
130 lines (100 loc) · 3.12 KB
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
127
128
129
130
//===- Device.h - Offload API Device API ----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
//
//===----------------------------------------------------------------------===//
#ifndef OFFLOADTEST_API_DEVICE_H
#define OFFLOADTEST_API_DEVICE_H
#include "Config.h"
#include "API/API.h"
#include "API/Capabilities.h"
#include "API/CommandBuffer.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Support/Error.h"
#include <memory>
#include <string>
namespace llvm {
class raw_ostream;
} // namespace llvm
namespace offloadtest {
struct Pipeline;
struct DeviceConfig {
bool EnableDebugLayer = false;
bool EnableValidationLayer = false;
};
enum class MemoryLocation {
GpuOnly,
CpuToGpu,
GpuToCpu,
};
struct BufferCreateDesc {
MemoryLocation Location;
};
class Buffer {
public:
virtual ~Buffer() = default;
Buffer(const Buffer &) = delete;
Buffer &operator=(const Buffer &) = delete;
protected:
Buffer() = default;
};
class Fence {
public:
virtual ~Fence() = default;
Fence(const Fence &) = delete;
Fence &operator=(const Fence &) = delete;
virtual uint64_t getFenceValue() = 0;
virtual llvm::Error waitForCompletion(uint64_t SignalValue) = 0;
protected:
Fence() = default;
};
class Queue {
public:
virtual ~Queue() = 0;
protected:
Queue() = default;
};
class Device {
protected:
std::string Description;
std::string DriverName;
public:
virtual const Capabilities &getCapabilities() = 0;
virtual llvm::StringRef getAPIName() const = 0;
virtual GPUAPI getAPI() const = 0;
virtual llvm::Error executeProgram(Pipeline &P) = 0;
virtual Queue &getGraphicsQueue() = 0;
virtual llvm::Expected<std::unique_ptr<Fence>>
createFence(llvm::StringRef Name) = 0;
virtual llvm::Expected<std::shared_ptr<Buffer>>
createBuffer(std::string Name, BufferCreateDesc &Desc,
size_t SizeInBytes) = 0;
virtual void printExtra(llvm::raw_ostream &OS) {}
virtual llvm::Expected<std::unique_ptr<CommandBuffer>> createCommandBuffer() {
return llvm::createStringError(
std::errc::not_supported,
"createCommandBuffer not implemented for this backend");
}
virtual ~Device() = 0;
llvm::StringRef getDescription() const { return Description; }
llvm::StringRef getDriverName() const { return DriverName; }
};
llvm::Error
initializeDX12Devices(const DeviceConfig Config,
llvm::SmallVectorImpl<std::unique_ptr<Device>> &Devices);
llvm::Error initializeVulkanDevices(
const DeviceConfig Config,
llvm::SmallVectorImpl<std::unique_ptr<Device>> &Devices);
llvm::Error
initializeMetalDevices(const DeviceConfig Config,
llvm::SmallVectorImpl<std::unique_ptr<Device>> &Devices);
llvm::Expected<llvm::SmallVector<std::unique_ptr<Device>>>
initializeDevices(const DeviceConfig Config);
} // namespace offloadtest
#endif // OFFLOADTEST_API_DEVICE_H