forked from MartinPersson/HOTlab
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhologram.cpp
66 lines (52 loc) · 1.77 KB
/
hologram.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
#include <cuda_runtime_api.h>
#include "common/data_format.hpp"
#include "common/phonebook.hpp"
#include "common/plugin.hpp"
#include "common/switchboard.hpp"
#include "hologram.h"
using namespace ILLIXR;
class hologram : public plugin {
public:
hologram(std::string name_, phonebook* pb_)
: plugin{name_, pb_}
, sb{pb->lookup_impl<switchboard>()}
{
bool ret = HLG_initialize();
if (!ret) {
throw std::runtime_error{"Hologram Initialization failed (" + std::to_string(ret) + ")"};
}
cudaEventCreate(&_start);
cudaEventCreate(&_stop);
sb->schedule<hologram_input>(id, "hologram_in", [&](switchboard::ptr<const hologram_input> datum, size_t) {
process(datum);
});
}
// Destructor (dumps data to stdout for analysis)
virtual ~hologram() override {
for (int i = 0; i < _start_durations.size(); ++i) {
std::cout << "gpu_timer,hologram," << i << ",0,0," << (_stop_durations[i] - _start_durations[i]) * 1000000 << "\n";
}
HLG_cleanup();
}
// Callback function
void process(switchboard::ptr<const hologram_input> datum) {
_start_durations.push_back(_total_gpu_time);
cudaEventRecord(_start, 0);
HLG_process();
cudaEventRecord(_stop, 0);
cudaEventSynchronize(_stop);
float elapsed_time;
cudaEventElapsedTime(&elapsed_time, _start, _stop);
_total_gpu_time += elapsed_time;
_stop_durations.push_back(_total_gpu_time);
}
private:
const std::shared_ptr<switchboard> sb;
// Timing
cudaEvent_t _start;
cudaEvent_t _stop;
std::vector<float> _start_durations;
std::vector<float> _stop_durations;
float _total_gpu_time = 0;
};
PLUGIN_MAIN(hologram)