-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathspammyboi.cpp
93 lines (74 loc) · 2.75 KB
/
spammyboi.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
87
88
89
90
91
92
93
#include <float.h>
#include <iostream>
#include <thread>
#include "udmalib/udma.h"
#include "proto/fpga_rpc_c.h"
#define max32 (0xffffffff)
#define top32(x) (x >> 32 & max32)
#define bot32(x) (x & max32)
// program config
int spamthreads = 8; // number of concurrent rpc connections
int spamrequest = 8; // number of concurrent requests per connection
int inflight = spamthreads * spamrequest; // max inflight requests
// hardware config
std::string hardware_name = "Partial_mandelbrot";
int width = 640, height = 480, iters = 255;
double cre = -0.36, cim = 0.641, zoom = 0.01;
int fixpbits = 29;
double fixpfactor = 1 << fixpbits;
uint64_t float2fix(double a) {
return (uint64_t)(int64_t) (a * fixpfactor);
}
// thread status management
bool shutdownRequested = false;
bool threadError = false;
// sets up the parameters for the hardware unit
void initParams(int width, int height, double cre, double cim, double zoom, int iters, uint64_t buffer, std::map<std::string, uint32_t> ¶ms) {
params["ImageWidth"] = width;
params["ImageHeight"] = height;
params["MaxIterations"] = iters;
params["cRe_1"] = bot32(float2fix(cre));
params["cRe_2"] = top32(float2fix(cre));
params["cIm_1"] = bot32(float2fix(cim));
params["cIm_2"] = top32(float2fix(cim));
params["zoom_1"] = bot32(float2fix(zoom));
params["zoom_2"] = top32(float2fix(zoom));
params["display_1"] = bot32(buffer);
params["display_2"] = top32(buffer);
}
// client to constantly request same jobs over and over
void spamClient(int cno) {
std::cout << "Starting spam client thread no " << cno << std::endl;
// get fpga rpc client instance
FPGARPCClient fpgaRpc;
// get free udma buffer from daemon
UdmaRepo repo;
int bufno = fpgaRpc.Alloc();
if (bufno < 0) throw std::runtime_error("Failed to get buffer from daemon");
UdmaDevice *device = repo.device(bufno);
uint64_t bufferPhy = device->phys_addr;
int chunksize = width * height;
// build joblist for submission
std::vector<Job> jobs;
for (int i = 0; i < spamrequest; i++) {
uint64_t phyaddr = bufferPhy + chunksize * i;
Job& job = jobs.emplace_back();
job.accname = "Partial_mandelbrot";
initParams(width, height, cre, cim, zoom, iters, phyaddr, job.params);
}
while (!shutdownRequested && !threadError)
fpgaRpc.Run(jobs);
device->unmap();
fpgaRpc.Free(bufno);
std::cout << "Closing spam client thread no " << cno << std::endl;
}
int main(int argc, char **argv) {
std::cout << "Starting client spammer" << std::endl;
std::vector<std::thread> threads;
for (int cno = 0; cno < spamthreads; cno++) {
threads.emplace_back(spamClient, cno);
}
for (std::thread& thread : threads)
thread.join();
return 0;
}