-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamd-issue.cpp
86 lines (75 loc) · 2.27 KB
/
amd-issue.cpp
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
#include <vector>
#include <iostream>
#include <easyvk.h>
#include <cassert>
#include <vector>
#include <unistd.h>
int main(int argc, char* argv[]) {
int workgroupSize = 128;
int numWorkgroups = 1;
int deviceID = 0;
bool enableValidationLayers = false;
int c;
while ((c = getopt (argc, argv, "vct:w:d:")) != -1)
switch (c)
{
case 't':
workgroupSize = atoi(optarg);
break;
case 'w':
numWorkgroups = atoi(optarg);
break;
case 'v':
enableValidationLayers = true;
break;
case 'd':
deviceID = atoi(optarg);
break;
case '?':
if (optopt == 't' || optopt == 'w')
std::cerr << "Option -" << optopt << "requires an argument\n";
else
std::cerr << "Unknown option" << optopt << "\n";
return 1;
default:
abort ();
}
auto size = numWorkgroups * workgroupSize;
// Initialize instance.
auto instance = easyvk::Instance(enableValidationLayers);
// Get list of available physical devices.
auto physicalDevices = instance.physicalDevices();
// Create device from first physical device.
auto device = easyvk::Device(instance, physicalDevices.at(deviceID));
std::cout << "Using device: " << device.properties.deviceName << "\n";
std::cout << "Device subgroup size: " << device.subgroupSize() << "\n";
// Define the buffers to use in the kernel.
auto out = easyvk::Buffer(device, size, sizeof(uint32_t));
auto partition = easyvk::Buffer(device, 1, sizeof(uint32_t));
auto debug = easyvk::Buffer(device, 1, sizeof(uint32_t));
partition.store<uint>(0, 42);
out.clear();
std::vector<easyvk::Buffer> bufs = {out, partition, debug};
std::vector<uint32_t> spvCode =
#include "build/amd-issue.cinit"
;
auto program = easyvk::Program(device, spvCode, bufs);
program.setWorkgroups(numWorkgroups);
program.setWorkgroupSize(workgroupSize);
// Run the kernel.
program.initialize("test");
float time = program.runWithDispatchTiming();
std::cout << "debug: " << debug.load<uint>(0) << "\n";
// Check the output.
for (int i = 0; i < size; i++) {
std::cout << "out[" << i << "]: " << out.load<uint>(i) << "\n";
}
// Cleanup.
program.teardown();
out.teardown();
partition.teardown();
debug.teardown();
device.teardown();
instance.teardown();
return 0;
}