Commit 230065be by songxinkai

async ram

parent 29ddcdc3
#!/bin/bash
bazel build --copt="-DRAMULATOR" //ramulator:main
bazel build --copt="-DRAMULATOR" //ramulator:testram
bazel build --copt="-DRAMULATOR" //ramulator:testram_break
1. burst len是多长?能控制吗?
2. 调用一次send能读到多少数据?
3. Dram的频率是多少?和处理器怎么适配?
cc_binary(
name="testram_break",
srcs=[
"testram_break.cpp",
],
deps=[
"ram",
],
copts=[
"-O3",
"-std=c++11",
"-g",
"-Wall",
],
)
cc_binary(
name="testram",
srcs=[
"testram.cpp",
......
......@@ -5,7 +5,7 @@
template<typename T>
Ram<T>::Ram(const std::string& config_file){
clk_ = 0;
processor_frequency_ratio_ = 1;
frequency_ = 1;
Config configs(config_file);
const std::string& standard = configs["standard"];
assert(standard != "" || "DRAM standard should be specified.");
......@@ -93,32 +93,47 @@ void Ram<T>::InitMemory(const Config& configs, T* spec){
memory_ = std::make_shared<Memory<T, Controller> >(configs, ctrls);
}
// Loop: memory_->tick()
template<typename T>
long Ram<T>::AccessMemory(const long req_addr, const Request::Type req_type){
long tmp_clk = 0;
bool data_return = false;
long req_addr_param = req_addr;
auto req_type_param = req_type;
auto callback = std::function<void(Request&)>([&data_return](Request& rq){data_return = true;});
Request req(req_addr_param, req_type_param, callback, 0);
memory_->send(req);
while (!data_return){
void Ram<T>::WaitUntil(const double time){
long ram_time = long(std::ceil(time * frequency_));
while (clk_ < ram_time){
memory_->tick();
clk_ ++;
tmp_clk ++;
}
return ConvertCyclesRam2Processor(tmp_clk);
}
// Loop: memory_->tick()
template<typename T>
long Ram<T>::AccessMemory(const long send_clk_processor, const long req_addr, const Request::Type req_type){
long send_clk = ConvertCyclesRam2Processor(send_clk_processor);
long tmp_clk = 0;
while (clk_ < send_clk){
void Ram<T>::WaitFor(const double time){
long ram_time = long(std::ceil(time * this->frequency_));
for (long i = 0; i < ram_time; ++i){
memory_->tick();
clk_ ++;
tmp_clk ++;
}
}
// memory_->send() and memory_->tick()
template<typename T>
void Ram<T>::AccessCommand(const long req_addr, const Request::Type req_type){
bool data_return = false;
long req_addr_param = req_addr;
auto req_type_param = req_type;
auto clk = this->clk_;
auto callback = std::function<void(Request&)>(
[&data_return, clk, this](Request& rq){
data_return = true;
std::cout << "send at: " << clk << ", recieve at: " << this->clk_ << " (" << this->clk_-clk << ")" << std::endl;
});
Request req(req_addr_param, req_type_param, callback, 0);
memory_->send(req);
memory_->tick();
clk_++;
}
template<typename T>
double Ram<T>::AccessAndWaitUntilReturn(const long req_addr, const Request::Type req_type){
long tmp_clk = 0;
bool data_return = false;
long req_addr_param = req_addr;
auto req_type_param = req_type;
......@@ -130,28 +145,27 @@ long Ram<T>::AccessMemory(const long send_clk_processor, const long req_addr, co
clk_ ++;
tmp_clk ++;
}
return ConvertCyclesRam2Processor(tmp_clk);
return ConvertRamCycle2Realtime(tmp_clk);
}
template<typename T>
long Ram<T>::ConvertCyclesRam2Processor(const long cycles){
return long(double(cycles) * processor_frequency_ratio_);
double Ram<T>::ConvertRamCycle2Realtime(const long cycles){
return double(cycles) / frequency_;
}
template<typename T>
long Ram<T>::ConvertCyclesProcessor2Ram(const long cycles){
return long(double(cycles) / processor_frequency_ratio_);
long Ram<T>::ConvertRealtime2RamCycle(const double realtime){
return long(double(realtime) * frequency_);
}
template<typename T>
void Ram<T>::SetProcessorFrequencyRatio(const double r){
void SetProcessorFrequencyRatio(const double r);
this->processor_frequency_ratio_ = r;
void Ram<T>::SetFrequency(const double r){
this->frequency_ = r;
}
template<typename T>
long Ram<T>::GetClockProcessor(){
return this->clk_ * processor_frequency_ratio_;
double Ram<T>::GetClockRealtime(){
return double(this->clk_) * frequency_;
}
template<typename T>
......
......@@ -32,16 +32,21 @@ class Ram{
public:
Ram(const std::string& config_file);
~Ram();
long AccessMemory(const long req_addr, const Request::Type req_type);
long AccessMemory(const long send_clk_processor, const long req_addr, const Request::Type req_type);
long ConvertCyclesRam2Processor(const long cycles);
long ConvertCyclesProcessor2Ram(const long cycles);
void SetProcessorFrequencyRatio(const double r);
long GetClockProcessor();
long GetClockRam();
// Loop: memory_->tick()
void WaitUntil(const double time);
void WaitFor(const double time);
// memory_->send() and memory_->tick()
void AccessCommand(const long req_addr, const Request::Type req_type);
// memory_->send() and Loop: memory_->tick(), return: realtime from send to return
double AccessAndWaitUntilReturn(const long req_addr, const Request::Type req_type);
double ConvertRamCycle2Realtime(const long ram_cycle);
long ConvertRealtime2RamCycle(const double realtime);
void SetFrequency(const double r);
double GetClockRealtime(); // unit: ns
long GetClockRam(); // unit: ram cycle
protected:
void InitMemory(const Config& configs, T* spec);
double processor_frequency_ratio_;
double frequency_; // unit: Ghz
long clk_;
std::shared_ptr<Memory<T, Controller> > memory_;
};
......@@ -12,12 +12,12 @@ int main(int argc, const char *argv[]){
return 0;
}
Ram<ramulator::DDR3> ram(argv[1]);
ram.SetProcessorFrequencyRatio(4.0);
ram.SetFrequency(1.0);
int addr_interval = std::stoi(argv[2]);
long last_access_time = -1;
int same_access_time_count = 0;
for (int i = 0; i < 1000; ++i){
long access_time = ram.AccessMemory(long(20734016 + i * addr_interval), ramulator::Request::Type::READ);
long access_time = ram.AccessAndWaitUntilReturn(long(20734016 + i * addr_interval), ramulator::Request::Type::READ);
if (last_access_time != access_time && last_access_time > 0){
cout << "access id: " << i << ", cycles: " << last_access_time << " (" << same_access_time_count << ")" << endl;
same_access_time_count = 1;
......@@ -26,6 +26,6 @@ int main(int argc, const char *argv[]){
}
last_access_time = access_time;
}
std::cout << "total cycles: " << ram.GetClockProcessor() << std::endl;
std::cout << "total cycles: " << ram.GetClockRealtime() << std::endl;
return 0;
}
#include "ram.h"
#include <iostream>
#include <string>
using namespace ramulator;
int main(int argc, const char *argv[]){
if (argc < 3) {
printf("Usage: %s <configs-file> <memory access interval>\n"
"Example: %s ramulator-configs.cfg 16\n", argv[0], argv[0]);
return 0;
}
Ram<ramulator::DDR3> ram(argv[1]);
ram.SetFrequency(1.0);
int addr_interval = std::stoi(argv[2]);
for (int i = 0; i < 1000; ++i){
ram.AccessCommand(long(20734016 + i * addr_interval), ramulator::Request::Type::READ);
ram.WaitFor(10);
}
ram.WaitUntil(80000);
std::cout << "total cycles: " << ram.GetClockRealtime() << std::endl;
return 0;
}
#!/bin/bash
./bazel-bin/ramulator/testram ./configs/DDR3-config.cfg $1
./bazel-bin/ramulator/testram_break ./configs/DDR3-config.cfg $1
./bazel-bin/ramulator/main ./configs/DDR3-config.cfg $1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment