Home >Database >Mysql Tutorial >Multi2sim、Dramsim链接

Multi2sim、Dramsim链接

WBOY
WBOYOriginal
2016-06-07 15:26:251898browse

简介: 系统结构实验常用的工具是仿真器simulator。Multi2sim是多核时钟精确仿真器,支持可变的存储层次结构,网络链接目前只支持Bus和P2P,但是对于内存的仿真只是简单返回200cycle延迟,对于研究内存控制器有很大的限制。DRAMsim是内存时钟精确仿真器。于

简介:

系统结构实验常用的工具是仿真器simulator。Multi2sim是多核时钟精确仿真器,支持可变的存储层次结构,网络链接目前只支持Bus和P2P,但是对于内存的仿真只是简单返回200cycle延迟,对于研究内存控制器有很大的限制。DRAMsim是内存时钟精确仿真器。于是本文的工作是把Multi2sim与DRAMsim相连接实现更强大的功能。


源码:

1、Multi2sim: A CPU-GPU Model for Heterogeneous Computing

CSDN下载地址:http://download.csdn.net/detail/koala002/3857207

2、DRAMsim: DRAMSim2 is a cycle accurate model of a DRAM memory controller

CSDN下载地址:http://download.csdn.net/detail/koala002/3857463


步骤:

1、解决C++与C程序链接问题

Multi2sim与DRAMsim接口文件:由于Automake工具族实现对*.c后缀文件使用CC变量编译器,*.cpp后缀使用CXX变量编译器,所以更改后缀名为.cpp

libcachesystem/cachesystem.cpp

首先在文件开头包含头文件,定义内存读写处理函数,全局定义一个内存实例指针

#ifdef MACRO_DRAM_SIM
#include "../libdram/MemorySystem.h"

class some_object
{
	public: 
		void read_complete(unsigned, uint64_t, uint64_t);
		void write_complete(unsigned, uint64_t, uint64_t);
		int add_one_and_run();
};
/* callback functors */
void some_object::read_complete(unsigned id, uint64_t address, uint64_t clock_cycle)
{
	//esim_schedule_event(EV_MOESI_FIND_AND_LOCK_FINISH, stack, ccache->lat);
	//printf("[Callback] read complete: %d 0x%lx cycle=%lu\n", id, address, clock_cycle);
}

void some_object::write_complete(unsigned id, uint64_t address, uint64_t clock_cycle)
{
	//esim_schedule_event(EV_MOESI_FIND_AND_LOCK_FINISH, stack, ccache->lat);
	//printf("[Callback] write complete: %d 0x%lx cycle=%lu\n", id, address, clock_cycle);
}

/* FIXME: this may be broken, currently */
void power_callback(double a, double b, double c, double d)
{
	printf("power callback: %0.3f, %0.3f, %0.3f, %0.3f\n",a,b,c,d);
}

/* init one dramsim instance */
class MemorySystem* g_dramsim_memory;

#endif
其次,cache_system_init是存储层次建立函数,申请一个内存实例,并且注册读写函数
#ifdef MACRO_DRAM_SIM
    /* new one instance */
    g_dramsim_memory= new MemorySystem(0, "ini/DDR2_micron_16M_8b_x8_sg3E.ini",\
        "system.ini", "/home/jyq/multi2sim-3.1.1/src/libdram", "resultsfilename", 1024*500);
    /* create and register our callback functions */
	Callback_t *read_cb = new Callback<some_object void unsigned uint64_t>(new some_object, &some_object::read_complete);
	Callback_t *write_cb = new Callback<some_object void unsigned uint64_t>(new some_object, &some_object::write_complete);
    g_dramsim_memory->RegisterCallbacks(read_cb, write_cb, power_callback);

#endif
</some_object></some_object>

libcachesystem/moesi.cpp:一致性协议操作,读写操作 

首先,头文件包含,并且注意代码快两端加入extern "C",以保证和原来代码兼容

#ifdef MACRO_DRAM_SIM
#include "../libdram/MemorySystem.h"
extern MemorySystem* g_dramsim_memory;
#endif

extern "C"{
#include "cachesystem.h"
其次,moesi_find_and_lock函数是找块函数,读写操作都需要此功能函数。

如果发现没有lonet,则为最后一级缓存,那么像内存插入transaction。

#ifdef MACRO_DRAM_SIM
        /* create a transaction and add it */
		if(!ccache->lonet){
			Transaction tr = Transaction(stack->read?DATA_READ:DATA_WRITE,stack->addr, stack);
			g_dramsim_memory->addTransaction(tr);
		}
#endif
原来代码内存仿真都只是简单返回200Cycles,所以这里改动如果发现是非内存读操作才直接加入延迟。否则等待内存操作返回后由读写完成注册函数处理。
#ifdef MACRO_DRAM_SIM
		/* Access latency */
		if(ccache->lonet ){
			esim_schedule_event(EV_MOESI_FIND_AND_LOCK_FINISH, stack, ccache->lat);
		}
#else
		esim_schedule_event(EV_MOESI_FIND_AND_LOCK_FINISH, stack, ccache->lat);
#endif

ibcpuarch/cpuarch.cpp

void cpu_run():实现时钟精确仿真,其中子函数cpu_stages()实现的是每周期取指、译码、执行、提交、写回流水线,所以在之后加入内存更新操作,这里注意处理器与内存的频率倍数。

#ifdef MACRO_DRAM_SIM
        /* Dramsim stage*/
        extern class MemorySystem* g_dramsim_memory;
        g_dramsim_memory->update();
#endif

2、为了代码最小改动,将DRAMSim编译成动态链接库,然后在链接处与Multi2sim代码相链接即可。

3、合并代码过程中,由于C标准允许void*指针赋给其他类型指针,但C++标注不允许,所以在改用g++编译某些源文件时需要在这些赋值位置强转类型。

4、Makefile改写可以参考automake、configure等资料。

5、本文只是基本大体改动框架,细节功能实现或者扩展功能还需要更细改写。




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn