Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data payload #39

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions resources/gem5_wrappers/ramulator2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,31 @@ Ramulator2::recvTimingReq(PacketPtr pkt)
if (pkt->isRead())
{
// Generate ramulator READ request and try to send to ramulator's memory system
int payload_size = pkt->getSize();
uint8_t* payload = new uint8_t[payload_size];
pkt->writeData(payload);
enqueue_success = ramulator2_frontend->
receive_external_requests(0, pkt->getAddr(), 0,
receive_external_requests(0, pkt->getAddr(), 0, payload, payload_size,
[this](Ramulator::Request& req) {
DPRINTF(Ramulator2, "Read to %ld completed.\n", req.addr);
auto& pkt_q = outstandingReads.find(req.addr)->second;
PacketPtr pkt = pkt_q.front();
pkt_q.pop_front();
if (!pkt_q.size())
if (!pkt_q.size()) {
if (ramulator2_frontend->data_is_set()) {
uint8_t* data_ptr = ramulator2_frontend->get_data();
// Presumably
// pkt->setData(data_ptr);
int ssize = pkt->getSize();
for (int i = 0; i < ssize; i++) {
std::cout << "Ramulator frontend data: " << (unsigned) data_ptr[i] << std::endl;
std::cout << "Expected gem5 data: " << (unsigned) toHostAddr(pkt->getAddr())[i] << std::endl;
//std::cout << "Expected gem5 data: " << (unsigned) pkt->getPtr<uint8_t>()[i] << std::endl;
}
ramulator2_frontend->reset_data();
}
outstandingReads.erase(req.addr);
}

// added counter to track requests in flight
--nbrOutstandingReads;
Expand All @@ -207,15 +223,19 @@ Ramulator2::recvTimingReq(PacketPtr pkt)
}
} else if (pkt->isWrite()) {
// Generate ramulator WRITE request and try to send to ramulator's memory system
enqueue_success = ramulator2_frontend->
receive_external_requests(1, pkt->getAddr(), 0,
int payload_size = pkt->getSize();
uint8_t* payload = new uint8_t[payload_size];
pkt->writeData(payload);
enqueue_success = ramulator2_frontend->
receive_external_requests(1, pkt->getAddr(), 0, payload, payload_size,
[this](Ramulator::Request& req) {
DPRINTF(Ramulator2, "Write to %ld completed.\n", req.addr);
auto& pkt_q = outstandingWrites.find(req.addr)->second;
PacketPtr pkt = pkt_q.front();
pkt_q.pop_front();
if (!pkt_q.size())
if (!pkt_q.size()) {
outstandingWrites.erase(req.addr);
}

// added counter to track requests in flight
--nbrOutstandingWrites;
Expand Down Expand Up @@ -259,7 +279,7 @@ void
Ramulator2::accessAndRespond(PacketPtr pkt)
{
DPRINTF(Ramulator2, "Access for address %lld\n", pkt->getAddr());

bool needsResponse = pkt->needsResponse();

access(pkt);
Expand Down
5 changes: 5 additions & 0 deletions src/base/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ Request::Request(AddrVec_t addr_vec, int type): addr_vec(addr_vec), type_id(type
Request::Request(Addr_t addr, int type, int source_id, std::function<void(Request&)> callback):
addr(addr), type_id(type), source_id(source_id), callback(callback) {};

Request::Request(Addr_t addr, int type, uint8_t* payload, int payload_size): addr(addr), type_id(type), payload(payload), payload_size(payload_size) {};

Request::Request(Addr_t addr, int type, int source_id, uint8_t* payload, int payload_size, std::function<void(Request&)> callback):
addr(addr), type_id(type), source_id(source_id), payload(payload), payload_size(payload_size), callback(callback) {};

} // namespace Ramulator

8 changes: 6 additions & 2 deletions src/base/request.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ struct Request {

std::function<void(Request&)> callback;

void* m_payload = nullptr; // Point to a generic payload
uint8_t* payload = 0; // Generic payload
int payload_size = 0;

Request(Addr_t addr, int type);
Request(Addr_t addr, int type, uint8_t* payload);
Request(Addr_t addr, int type, uint8_t* payload, int payload_size);
Request(AddrVec_t addr_vec, int type);
Request(Addr_t addr, int type, int source_id, std::function<void(Request&)> callback);
Request(Addr_t addr, int type, int source_id, uint8_t* payload, int payload_size, std::function<void(Request&)> callback);
};


Expand Down Expand Up @@ -73,4 +77,4 @@ struct ReqBuffer {
} // namespace Ramulator


#endif // RAMULATOR_BASE_REQUEST_H
#endif // RAMULATOR_BASE_REQUEST_H
38 changes: 38 additions & 0 deletions src/dram_controller/impl/scheduler/generic_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,42 @@ class FRFCFS : public IScheduler, public Implementation {
}
};

class FCFS : public IScheduler, public Implementation {
RAMULATOR_REGISTER_IMPLEMENTATION(IScheduler, FCFS, "FCFS", "FCFS DRAM Scheduler.")
private:
IDRAM* m_dram;

public:
void init() override { };

void setup(IFrontEnd* frontend, IMemorySystem* memory_system) override {
m_dram = cast_parent<IDRAMController>()->m_dram;
};

ReqBuffer::iterator compare(ReqBuffer::iterator req1, ReqBuffer::iterator req2) override {
if (req1->arrive <= req2->arrive) {
return req1;
} else {
return req2;
}
}

ReqBuffer::iterator get_best_request(ReqBuffer& buffer) override {
if (buffer.size() == 0) {
return buffer.end();
}

for (auto& req : buffer) {
req.command = m_dram->get_preq_command(req.final_command, req.addr_vec);
}

auto candidate = buffer.begin();
for (auto next = std::next(buffer.begin(), 1); next != buffer.end(); next++) {
candidate = compare(candidate, next);
}
return candidate;
}
};


} // namespace Ramulator
3 changes: 2 additions & 1 deletion src/frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ target_sources(

impl/memory_trace/loadstore_trace.cpp
impl/memory_trace/readwrite_trace.cpp
impl/memory_trace/loadstoredata_trace.cpp

impl/processor/simpleO3/simpleO3.cpp
impl/processor/simpleO3/core.h impl/processor/simpleO3/core.cpp
Expand All @@ -23,4 +24,4 @@ target_link_libraries(
ramulator
PRIVATE
ramulator-frontend
)
)
30 changes: 27 additions & 3 deletions src/frontend/frontend.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef RAMULATOR_FRONTEND_FRONTEND_H
#define RAMULATOR_FRONTEND_FRONTEND_H

#include <vector>
#include <string>
#include <functional>

Expand All @@ -19,6 +18,8 @@ class IFrontEnd : public Clocked<IFrontEnd>, public TopLevel<IFrontEnd> {
protected:
IMemorySystem* m_memory_system;
uint m_clock_ratio = 1;
uint8_t* m_payload = nullptr;
bool m_data_is_set = false;

public:
virtual void connect_memory_system(IMemorySystem* memory_system) {
Expand Down Expand Up @@ -55,10 +56,33 @@ class IFrontEnd : public Clocked<IFrontEnd>, public TopLevel<IFrontEnd> {
* (tries to) send to the memory system, and return if this is successful
*
*/
virtual bool receive_external_requests(int req_type_id, Addr_t addr, int source_id, std::function<void(Request&)> callback) { return false; }
virtual bool receive_external_requests(int req_type_id, Addr_t addr, int source_id,
std::function<void(Request&)> callback) { return false; }

virtual bool receive_external_requests(int req_type_id, Addr_t addr, int source_id, uint8_t* payload, int payload_size,
std::function<void(Request&)> callback) { return false; }

virtual void set_data(uint8_t* payload) {
if (m_payload != nullptr) delete(m_payload);
m_payload = payload;
m_data_is_set = true;
}

virtual void reset_data() {
m_data_is_set = false;
if (m_payload != nullptr) {
delete(m_payload);
m_payload = nullptr;
}
}

virtual uint8_t* get_data() { return m_payload; }

virtual bool data_is_set() { return m_data_is_set; }

};

} // namespace Ramulator


#endif // RAMULATOR_FRONTEND_FRONTEND_H
#endif // RAMULATOR_FRONTEND_FRONTEND_H
7 changes: 6 additions & 1 deletion src/frontend/impl/external_wrapper/gem5_frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ class GEM5 : public IFrontEnd, public Implementation {
return m_memory_system->send({addr, req_type_id, source_id, callback});
}

bool receive_external_requests(int req_type_id, Addr_t addr, int source_id,
uint8_t* payload, int payload_size, std::function<void(Request&)> callback) override {
return m_memory_system->send({addr, req_type_id, source_id, payload, payload_size, callback});
}

private:
bool is_finished() override { return true; };
};

} // namespace Ramulator
} // namespace Ramulator
126 changes: 126 additions & 0 deletions src/frontend/impl/memory_trace/loadstoredata_trace.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#include <cstdint>
#include <filesystem>
#include <fstream>

#include "frontend/frontend.h"
#include "base/exception.h"

namespace Ramulator {

namespace fs = std::filesystem;

class LoadStoreDataTrace : public IFrontEnd, public Implementation {
RAMULATOR_REGISTER_IMPLEMENTATION(IFrontEnd, LoadStoreDataTrace, "LoadStoreDataTrace", "Load/Store memory address trace with data.")

private:
struct Trace {
bool is_write;
Addr_t addr;
uint8_t* payload;
int payload_size;
};
std::vector<Trace> m_trace;

size_t m_trace_length = 0;
size_t m_curr_trace_idx = 0;

size_t m_trace_count = 0;

Logger_t m_logger;

public:
void init() override {
std::string trace_path_str = param<std::string>("path").desc("Path to the load store trace file.").required();
m_clock_ratio = param<uint>("clock_ratio").required();

m_logger = Logging::create_logger("LoadStoreDataTrace");
m_logger->info("Loading trace file {} ...", trace_path_str);
init_trace(trace_path_str);
m_logger->info("Loaded {} lines.", m_trace.size());
};


void tick() override {
const Trace& t = m_trace[m_curr_trace_idx];
bool request_sent = m_memory_system->send({t.addr, t.is_write ? Request::Type::Write : Request::Type::Read, t.payload, t.payload_size});
if (request_sent) {
m_curr_trace_idx = (m_curr_trace_idx + 1) % m_trace_length;
m_trace_count++;
}
};


private:
void init_trace(const std::string& file_path_str) {
fs::path trace_path(file_path_str);
if (!fs::exists(trace_path)) {
throw ConfigurationError("Trace {} does not exist!", file_path_str);
}

std::ifstream trace_file(trace_path);
if (!trace_file.is_open()) {
throw ConfigurationError("Trace {} cannot be opened!", file_path_str);
}

int line_count = 0;
std::string line;
while (std::getline(trace_file, line)) {
line_count++;
std::vector<std::string> tokens;
tokenize(tokens, line, " ");

if (tokens.size() < 2) {
throw ConfigurationError("Trace {} format invalid on line {} (Line has too few tokens)!", file_path_str, line_count);
}

bool is_write = false;
if (tokens[0] == "LD") {
if (tokens.size() != 3) {
for (int i = 0; i < tokens.size(); i++)
std::cout << i << ": " << tokens[i] << std::endl;
throw ConfigurationError("Trace {} format invalid on line {} (LD must have 3 tokens, not {})!", file_path_str, line_count, tokens.size());
}
is_write = false;
} else if (tokens[0] == "ST") {
if (tokens.size() < 4)
throw ConfigurationError("Trace {} format invalid on line {} (ST must have more tokens)!", file_path_str, line_count);
if (stoi(tokens[2]) < 1 && tokens.size() != 3 + stoi(tokens[2]))
throw ConfigurationError("Trace {} format invalid on line {} (ST has too few tokens)!", file_path_str, line_count);
is_write = true;
} else {
throw ConfigurationError("Trace {} format invalid on line {} (unknown command)!", file_path_str, line_count);
}

Addr_t addr = -1;
if (tokens[1].compare(0, 2, "0x") == 0 | tokens[1].compare(0, 2, "0X") == 0) {
addr = std::stoll(tokens[1].substr(2), nullptr, 16);
} else {
addr = std::stoll(tokens[1]);
}

uint8_t* payload = nullptr;
int payload_size = stoi(tokens[2]);
if (is_write) {
if (stoi(tokens[2]) >= 0 || stoi(tokens[2]) <= 255) {
payload = new uint8_t[payload_size];
for (int i = 0; i < payload_size; i++) {
payload[i] = (uint8_t) stoi(tokens[3 + i]);
}
}
}

m_trace.push_back({is_write, addr, payload, payload_size});
}

trace_file.close();

m_trace_length = m_trace.size();
};

// TODO: FIXME
bool is_finished() override {
return m_trace_count >= m_trace_length;
};
};

} // namespace Ramulator