forked from llvm/offload-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuffer.h
More file actions
61 lines (46 loc) · 1.54 KB
/
Copy pathBuffer.h
File metadata and controls
61 lines (46 loc) · 1.54 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
//===- Buffer.h - Offload API Buffer --------------------------------------===//
//
// 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_BUFFER_H
#define OFFLOADTEST_API_BUFFER_H
#include "API/API.h"
#include "API/Resources.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Error.h"
namespace offloadtest {
enum class BufferUsage {
Storage,
VertexBuffer,
};
struct BufferCreateDesc {
MemoryLocation Location;
BufferUsage Usage;
static BufferCreateDesc uploadBuffer() {
return BufferCreateDesc{MemoryLocation::CpuToGpu, BufferUsage::Storage};
}
};
class Buffer {
GPUAPI API;
public:
virtual ~Buffer();
virtual size_t getSizeInBytes() const = 0;
// Maps the buffer's memory for host access. Only valid for CpuToGpu and
// GpuToCpu buffers; returns an error for GpuOnly. Each successful map() must
// be paired with a call to unmap() before the buffer is used on the GPU.
virtual llvm::Expected<void *> map() = 0;
virtual void unmap() = 0;
Buffer(const Buffer &) = delete;
Buffer &operator=(const Buffer &) = delete;
GPUAPI getAPI() const { return API; }
protected:
explicit Buffer(GPUAPI API) : API(API) {}
};
} // namespace offloadtest
#endif // OFFLOADTEST_API_BUFFER_H