gpu2rtds.cpp 3.93 KB
Newer Older
Daniel Krebs's avatar
Daniel Krebs committed
1
2
3
#include <unistd.h>
#include <cstring>

Steffen Vogel's avatar
Steffen Vogel committed
4
#include <villas/log.hpp>
Daniel Krebs's avatar
Daniel Krebs committed
5
6
7
#include <villas/memory_manager.hpp>
#include <villas/fpga/ips/gpu2rtds.hpp>

8
using namespace villas::fpga::ip;
Daniel Krebs's avatar
Daniel Krebs committed
9
10
11
12
13
14
15

static Gpu2RtdsFactory factory;

bool Gpu2Rtds::init()
{
	Hls::init();

16
	auto &registers = addressTranslations.at(registerMemory);
Daniel Krebs's avatar
Daniel Krebs committed
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

	registerStatus = reinterpret_cast<StatusRegister*>(registers.getLocalAddr(registerStatusOffset));
	registerStatusCtrl = reinterpret_cast<StatusControlRegister*>(registers.getLocalAddr(registerStatusCtrlOffset));
	registerFrameSize = reinterpret_cast<uint32_t*>(registers.getLocalAddr(registerFrameSizeOffset));
	registerFrames = reinterpret_cast<uint32_t*>(registers.getLocalAddr(registerFrameOffset));

	maxFrameSize = getMaxFrameSize();
	logger->info("Max. frame size supported: {}", maxFrameSize);

	return true;
}

bool
Gpu2Rtds::startOnce(size_t frameSize)
{
	*registerFrameSize = frameSize;

	start();

	return true;
}

void Gpu2Rtds::dump(spdlog::level::level_enum logLevel)
{
	const auto frame_size = *registerFrameSize;
	auto status = *registerStatus;

	logger->log(logLevel, "Gpu2Rtds registers:");
	logger->log(logLevel, "  Frame size (words):       {:#x}", frame_size);
	logger->log(logLevel, "  Status:                   {:#x}", status.value);
	logger->log(logLevel, "    Running:            {}", (status.is_running ? "yes" : "no"));
	logger->log(logLevel, "    Frame too short:    {}", (status.frame_too_short ? "yes" : "no"));
	logger->log(logLevel, "    Frame too long:     {}", (status.frame_too_long ? "yes" : "no"));
	logger->log(logLevel, "    Frame size invalid: {}", (status.invalid_frame_size ? "yes" : "no"));
Steffen Vogel's avatar
wip    
Steffen Vogel committed
51
52
53
	logger->log(logLevel, "    Last count:         {}", (int) status.last_count);
	logger->log(logLevel, "    Last seq. number:   {}", (int) status.last_seq_nr);
	logger->log(logLevel, "    Max. frame size:    {}", (int) status.max_frame_size);
Daniel Krebs's avatar
Daniel Krebs committed
54
55
}

56
//bool Gpu2Rtds::startOnce(const MemoryBlock &mem, size_t frameSize, size_t dataOffset, size_t doorbellOffset)
Daniel Krebs's avatar
Daniel Krebs committed
57
//{
58
//	auto &mm = MemoryManager::get();
Daniel Krebs's avatar
Daniel Krebs committed
59

Steffen Vogel's avatar
Steffen Vogel committed
60
//	if (frameSize > maxFrameSize) {
Daniel Krebs's avatar
Daniel Krebs committed
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
//		logger->error("Requested frame size of {} exceeds max. frame size of {}",
//		              frameSize, maxFrameSize);
//		return false;
//	}

//	auto translationFromIp = mm.getTranslation(
//	                               getMasterAddrSpaceByInterface(axiInterface),
//	                               mem.getAddrSpaceId());

//	// set address of memory block in HLS IP
//	XGpu2Rtds_Set_baseaddr(&xInstance, translationFromIp.getLocalAddr(0));

//	XGpu2Rtds_Set_doorbell_offset(&xInstance, doorbellOffset);
//	XGpu2Rtds_Set_data_offset(&xInstance, dataOffset);
//	XGpu2Rtds_Set_frame_size(&xInstance, frameSize);

//	// prepare memory with all zeroes
//	auto translationFromProcess = mm.getTranslationFromProcess(mem.getAddrSpaceId());
//	auto memory = reinterpret_cast<void*>(translationFromProcess.getLocalAddr(0));
//	memset(memory, 0, mem.getSize());

//	// start IP
//	return start();
//}





//bool
//Gpu2Rtds::updateStatus()
//{
Steffen Vogel's avatar
Steffen Vogel committed
93
//	if (not XGpu2Rtds_Get_status_vld(&xInstance))
Daniel Krebs's avatar
Daniel Krebs committed
94
95
96
97
98
99
100
101
102
103
104
105
106
//		return false;

//	status.value = XGpu2Rtds_Get_status(&xInstance);

//	return true;
//}

size_t
Gpu2Rtds::getMaxFrameSize()
{
	*registerFrameSize = 0;

	start();
Steffen Vogel's avatar
Steffen Vogel committed
107
	while (not isFinished());
Daniel Krebs's avatar
Daniel Krebs committed
108

Steffen Vogel's avatar
Steffen Vogel committed
109
	while (not registerStatusCtrl->status_ap_vld);
Daniel Krebs's avatar
Daniel Krebs committed
110
111
112
113
114
115
116
117
118
119
120
121
122
123

	axilite_reg_status_t status = *registerStatus;

//	logger->debug("(*registerStatus).max_frame_size: {}", (*registerStatus).max_frame_size);
//	logger->debug("status.max_frame_size: {}", status.max_frame_size);

//	assert(status.max_frame_size == (*registerStatus).max_frame_size);

	return status.max_frame_size;
}

//void
//Gpu2Rtds::dumpDoorbell(uint32_t doorbellRegister) const
//{
124
//	auto &doorbell = reinterpret_cast<reg_doorbell_t&>(doorbellRegister);
Daniel Krebs's avatar
Daniel Krebs committed
125
126
127
128

//	logger->info("Doorbell register: {:#08x}", doorbell.value);
//	logger->info("  Valid:       {}", (doorbell.is_valid ? "yes" : "no"));
//	logger->info("  Count:       {}", doorbell.count);
Steffen Vogel's avatar
wip    
Steffen Vogel committed
129
//	logger->info("  Seq. number: {}", (int) doorbell.seq_nr);
Daniel Krebs's avatar
Daniel Krebs committed
130
131
//}