Commit 230065be by songxinkai

async ram

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