Ejemplo n.º 1
0
/* initialize the simulator */
void
sim_init(void)
{
  sim_num_refs = 0;

  /* allocate and initialize register file */
  regs_init(&regs);

  /* allocate and initialize memory space */
  mem = mem_create("mem");
  mem_init(mem);
}
Ejemplo n.º 2
0
void FrmEmuCreate(FrmEmu *self)
{
    /* Parent */
    EmuCreate(asEmu(self), "Fermi");

    /* Initialize */
    self->grids = list_create();
    self->pending_grids = list_create();
    self->running_grids = list_create();
    self->finished_grids = list_create();
    self->global_mem = mem_create();
    self->global_mem->safe = 0;
    self->global_mem_top = 0;
    self->total_global_mem_size = 1 << 31; /* 2GB */
    self->free_global_mem_size = 1 << 31; /* 2GB */
    self->const_mem = mem_create();
    self->const_mem->safe = 0;

    /* Virtual functions */
    asObject(self)->Dump = FrmEmuDump;
    asEmu(self)->DumpSummary = FrmEmuDumpSummary;
    asEmu(self)->Run = FrmEmuRun;
}
Ejemplo n.º 3
0
void X86ContextCreate(X86Context *self, X86Emu *emu)
{
	/* Baseline initialization */
	X86ContextDoCreate(self, emu);

	/* Loader */
	self->loader = x86_loader_create();

	/* Memory */
	self->address_space_index = emu->address_space_index++;
	self->mem = mem_create();
	self->spec_mem = spec_mem_create(self->mem);

	/* Signal handlers and file descriptor table */
	self->signal_handler_table = x86_signal_handler_table_create();
	self->file_desc_table = x86_file_desc_table_create();
}
Ejemplo n.º 4
0
void SIEmuCreate(SIEmu *self)
{
	/* Parent */
	EmuCreate(asEmu(self), "SouthernIslands");

	/* Initialize */
	self->video_mem = mem_create();
	self->video_mem->safe = 0;
	self->video_mem_top = 0;
	self->waiting_work_groups = list_create();
	self->running_work_groups = list_create();
	
	/* Set global memory to video memory by default */
	self->global_mem = self->video_mem;

	/* Virtual functions */
	asObject(self)->Dump = SIEmuDump;
	asEmu(self)->DumpSummary = SIEmuDumpSummary;
	asEmu(self)->Run = SIEmuRun;
}
Ejemplo n.º 5
0
/* load program into simulated state */
void
sim_load_prog(char *fname,		/* program to load */
	      int argc, char **argv,	/* program arguments */
	      char **envp)		/* program environment */
{
  /* load program text and data, set up environment, memory, and regs */
  ld_load_prog(fname, argc, argv, envp, &regs, mem, TRUE);

#ifdef TARGET_ALPHA
  /* pre-decode text segment */
  {
    unsigned i, num_insn = (ld_text_size + 3) / 4;

    fprintf(stderr, "** pre-decoding %u insts...", num_insn);

    /* allocate decoded text space */
    dec = mem_create("dec");

    for (i=0; i < num_insn; i++)
      {
	enum md_opcode op;
	md_inst_t inst;
	md_addr_t PC;

	/* compute PC */
	PC = ld_text_base + i * sizeof(md_inst_t);

	/* get instruction from memory */
	MD_FETCH_INST(inst, mem, PC);

	/* decode the instruction */
	MD_SET_OPCODE(op, inst);

	/* insert into decoded opcode space */
	MEM_WRITE_WORD(dec, PC << 1, (word_t)op);
	MEM_WRITE_WORD(dec, (PC << 1)+sizeof(word_t), inst);
      }
    fprintf(stderr, "done\n");
  }
#endif /* TARGET_ALPHA */
}
Ejemplo n.º 6
0
/* initialize the simulator */
void
sim_init(void)
{
  /* allocate and initialize register file */
  regs_init(&regs);

  /* allocate and initialize memory space */
  mem = mem_create("mem");
  mem_init(mem);

  // Initiate empty stage
  EMPTY_DE_BUF.inst.a = NOP;
  EMPTY_FD_BUF.inst.a = NOP;
  buf.fd.inst.a = NOP;
  buf.de.inst.a = NOP;
  buf.em.inst.a = NOP;
  buf.mw.inst.a = NOP;

  /* Initiate log */
  log_file = fopen("trace.txt", "w+");
}
Ejemplo n.º 7
0
/* initialize the simulator */
void
sim_init(void)
{
  /* allocate and initialize register file */
  regs_init(&regs);

  /* allocate and initialize memory space */
  mem = mem_create("mem");
  mem_init(mem);

  /* initialize stage latches*/
 
  /* IF/ID */
  fd.inst.a = NOP;
  fd.inst.b = 0;
  fd.PC = 0;
  fd.NPC = 0;

  /* ID/EX */
  de.inst.a = NOP;
  de.inst.b = 0;
  de.PC = 0;


  // de.latched = 0;
  /* EX/MEM */
  em.inst.a = NOP;
  em.inst.b = 0;
  em.PC = 0;
  em.oprand.out1 = DNA;
  em.oprand.out2 = DNA;


  /* MEM/WB */
  mw.inst.a = NOP;
  mw.inst.b = 0;
  mw.PC = 0;
  mw.oprand.out1 = DNA;
  mw.oprand.out2 = DNA;
}
Ejemplo n.º 8
0
void init_openstack_host(){
	if(g_openstack_host_network_id != NULL){
		mem_destroy(g_openstack_host_network_id);
	}
	g_openstack_host_network_id = mem_create(sizeof(openstack_network), OPENSTACK_NETWORK_MAX_NUM);

	if(g_openstack_host_subnet_id != NULL){
		mem_destroy(g_openstack_host_subnet_id);
	}
	g_openstack_host_subnet_id = mem_create(sizeof(openstack_subnet), OPENSTACK_SUBNET_MAX_NUM);

	if(g_openstack_host_port_id != NULL){
		mem_destroy(g_openstack_host_port_id);
	}
	g_openstack_host_port_id = mem_create(sizeof(openstack_port), OPENSTACK_PORT_MAX_NUM);


	if(g_openstack_host_node_id != NULL){
		mem_destroy(g_openstack_host_node_id);
	}
	g_openstack_host_node_id = mem_create(sizeof(openstack_node), OPENSTACK_NODE_MAX_NUM);

	if (g_openstack_security_group_id != NULL) {
		mem_destroy(g_openstack_security_group_id);
	}
	g_openstack_security_group_id = mem_create(sizeof(openstack_security), OPENSTACK_SECURITY_GROUP_MAX_NUM);

	if (g_openstack_host_security_id != NULL) {
		mem_destroy(g_openstack_host_security_id);
	}
	g_openstack_host_security_id = mem_create(sizeof(openstack_node), OPENSTACK_HOST_SECURITY_MAX_NUM);

	if (g_openstack_security_rule_id != NULL) {
		mem_destroy(g_openstack_security_rule_id);
	}
	g_openstack_security_rule_id = mem_create(sizeof(openstack_security_rule), OPENSTACK_SECURITY_RULE_MAX_NUM);

	g_openstack_host_network_list = NULL;
	g_openstack_host_subnet_list = NULL;
	g_openstack_host_port_list = NULL;
	return;
};
Ejemplo n.º 9
0
magnify ()
{
	struct pixrect *prr, *prw, *prc;

	RCOLORS * rcolors;
	WCOLORS * wcolors;
	WCOLORS * ccolors;

	int x1, x2, y1, y2;
	int last_x1, last_x2;
	int last_y1, last_y2;
	int x, y;
	int i, j, k, l;

	prr = mem_create ( 40, 40, 8 );
	prw = mem_create ( 200, 200, 8 );
	prc = mem_create ( 200, 200, 8 );

	rcolors = (RCOLORS *)mpr_d(prr)->md_image;
	wcolors = (WCOLORS *)mpr_d(prw)->md_image;
	ccolors = (WCOLORS *)mpr_d(prw)->md_image;

	for ( i = 0; i < 200; i++ )
	for ( j = 0; j < 200; j++ )
	{
		wcolors[i][j] = ccolors[i][j] = 8;
	}

	for ( i = (1<<3); i < (1<<3)+8; i++ ) mapcolor ( i,   0,   0,   0 );
	for ( i = (2<<3); i < (2<<3)+8; i++ ) mapcolor ( i, 255,   0,   0 );
	for ( i = (3<<3); i < (3<<3)+8; i++ ) mapcolor ( i,   0, 255,   0 );
	for ( i = (4<<3); i < (4<<3)+8; i++ ) mapcolor ( i, 255, 255,   0 );
	for ( i = (5<<3); i < (5<<3)+8; i++ ) mapcolor ( i,   0,   0, 255 );
	for ( i = (6<<3); i < (6<<3)+8; i++ ) mapcolor ( i, 255,   0, 255 );
	for ( i = (7<<3); i < (7<<3)+8; i++ ) mapcolor ( i,   0, 255, 255 );
	for ( i = (8<<3); i < (8<<3)+8; i++ ) mapcolor ( i, 255, 255, 255 );

	pw_putcolormap ( pw, 0, 64, red, green, blue );

	writemask ( 7 << 3 );

	last_x1 = last_x2 = 0;
	last_y1 = last_y2 = 0;

	for ( ;; )
	{
/*
			for ( dev = 0; dev == 0; )
			{
*/
				notify_dispatch ();

				x = dev_x;
				y = dev_y;

				if ( x < 20 || x > (width-20) ) continue;
				if ( y < 20 || y > (height-20) ) continue;

				x1 = x - 20; x2 = x + 20;
				y1 = y - 20; y2 = y + 20;

				if ( x1 == last_x1 && y1 == last_y1 ) continue;

				color = 0;
				recti ( last_x1, last_y1, last_x1+40, last_y1+40 );
				color = 16;
				recti ( x1, y1, x2, y2 );

				last_x1 = x1; last_y1 = y1;
/*
			}
*/
		if ( dev == MS_LEFT )
			break;

			pw_write ( pw, last_x2, last_y2, 200, 200, PIX_SRC, prc, 0, 0 );

			pw_read ( prr, 0, 0, 40, 40, PIX_SRC, pw, x-20, height-y-20 );

		recti ( x1, y1, x2, y2 );

			for ( i = 0; i < 40; i++ )
			{
				for ( j = 0; j < 40; j++ )
				{
					for ( k = 1; k <= 3; k++ )
					for ( l = 0; l <= 4; l++ )
					{
						wcolors[i*5+k][j*5+l] = ((rcolors[i][j]&7)+1) << 3;
					}
				}
			}

			x1 = x + 60;
			if ( x1 > (width-200) )
				x1 = x - 260;
			x2 = x1 + 199;

			y1 = y - 100;
			if ( y1 < 0 )
				y1 = 0;
			if ( y1 > (height-200) )
				y1 = height-200;
			y2 = y1 + 199;

			pw_write ( pw, x1, height - y2, 200, 200, PIX_SRC, prw, 0, 0 );

			color = 16;
			recti ( x1, y1, x2, y2 );

			last_x2 = x1; last_y2 = height - y2;
	}

	pr_destroy ( prr );
	pr_destroy ( prw );
	pr_destroy ( prc );

	clear ();

	writemask ( -1 );
}
Ejemplo n.º 10
0
struct si_work_group_t *si_work_group_create(unsigned int work_group_id, 
	struct si_ndrange_t *ndrange)
{
	struct si_bin_enc_user_element_t *user_elements;
	struct si_wavefront_t *wavefront;
	struct si_work_group_t *work_group;
	struct si_work_item_t *work_item;

	int i;
	int lid;
	int lidx, lidy, lidz;
	int tid;
	int user_element_count;
	int wavefront_id;
	int wavefront_offset;
	int work_item_id;
	int work_item_gidx_start;
	int work_item_gidy_start;
	int work_item_gidz_start;

	/* Number of in work-items in work-group */
	unsigned int work_items_per_group = ndrange->local_size3[0] * 
		ndrange->local_size3[1] * ndrange->local_size3[2];
	assert(work_items_per_group > 0);

	/* Number of wavefronts in work-group */
	unsigned int wavefronts_per_group = (work_items_per_group + 
		(si_emu_wavefront_size - 1)) / si_emu_wavefront_size;
	assert(wavefronts_per_group > 0);

	/* Initialize */
	work_group = xcalloc(1, sizeof(struct si_work_group_t));
	work_group->id = work_group_id;
	work_group->ndrange = ndrange;

	/* Create LDS */
	work_group->lds_module = mem_create();
	work_group->lds_module->safe = 0;

	/* Allocate pointers for work-items (will actually be created when
	 * wavefronts are created) */
	work_group->work_items = xcalloc(si_emu_wavefront_size * 
		wavefronts_per_group, sizeof(void *));
	work_group->wavefronts = xcalloc(wavefronts_per_group, sizeof(void *));
	work_group->wavefront_count = wavefronts_per_group;

	/* Allocate wavefronts and work-items */
	SI_FOREACH_WAVEFRONT_IN_WORK_GROUP(work_group, wavefront_id)
	{
		work_group->wavefronts[wavefront_id] = si_wavefront_create(
			work_group->id * wavefronts_per_group + wavefront_id,
			work_group);

		wavefront = work_group->wavefronts[wavefront_id];

		SI_FOREACH_WORK_ITEM_IN_WAVEFRONT(wavefront, work_item_id)
		{
			wavefront_offset = wavefront_id * si_emu_wavefront_size;

			work_group->work_items[wavefront_offset+work_item_id] = 
				wavefront->work_items[work_item_id];
			work_group->work_items[wavefront_offset+work_item_id]->
				work_group = work_group;
		}
Ejemplo n.º 11
0
Archivo: main.c Proyecto: malind/bam
/* *** */
static int bam(const char *scriptfile, const char **targets, int num_targets)
{
	struct CONTEXT context;
	int build_error = 0;
	int setup_error = 0;
	int report_done = 0;

	/* build time */
	time_t starttime  = time(0x0);

	/* create the cache and tmp directory */
	file_createdir(".bam");
	
	/* zero out and create memory heap, graph */
	memset(&context, 0, sizeof(struct CONTEXT));
	context.graphheap = mem_create();
	context.deferredheap = mem_create();
	context.graph = node_graph_create(context.graphheap);
	context.exit_on_error = option_abort_on_error;
	context.buildtime = timestamp();

	/* create lua context */
	/* HACK: Store the context pointer as the userdata pointer to the allocator to make
		sure that we have fast access to it. This makes the context_get_pointer call very fast */
	context.lua = lua_newstate(lua_alloctor_malloc, &context);

	/* install panic function */
	lua_atpanic(context.lua, lf_panicfunc);

	/* load cache (thread?) */
	if(option_no_cache == 0)
	{
		/* create a hash of all the external variables that can cause the
			script to generate different results */
		hash_t cache_hash = 0;
		char hashstr[64];
		int i;
		for(i = 0; i < option_num_scriptargs; i++)
			cache_hash = string_hash_add(cache_hash, option_scriptargs[i]);

		string_hash_tostr(cache_hash, hashstr);
		sprintf(cache_filename, ".bam/%s", hashstr);

		event_begin(0, "cache load", cache_filename);
		context.cache = cache_load(cache_filename);
		event_end(0, "cache load", NULL);
	}

	/* do the setup */
	setup_error = bam_setup(&context, scriptfile, targets, num_targets);

	/* done with the loopup heap */
	mem_destroy(context.deferredheap);

	/* close the lua state */
	lua_close(context.lua);
	
	/* do actions if we don't have any errors */
	if(!setup_error)
	{
		event_begin(0, "prepare", NULL);
		build_error = context_build_prepare(&context);
		event_end(0, "prepare", NULL);
		
		if(!build_error)
		{
			event_begin(0, "prioritize", NULL);
			build_error = context_build_prioritize(&context);
			event_end(0, "prioritize", NULL);
		}

		if(!build_error)
		{
			if(option_debug_nodes) /* debug dump all nodes */
				node_debug_dump(context.graph);
			else if(option_debug_nodes_detailed) /* debug dump all nodes detailed */
				node_debug_dump_detailed(context.graph);
			else if(option_debug_jobs) /* debug dump all jobs */
				node_debug_dump_jobs(context.graph);
			else if(option_debug_joblist) /* debug dumps the joblist */
				context_dump_joblist(&context);
			else if(option_debug_dot) /* debug dump all nodes as dot */
				node_debug_dump_dot(context.graph, context.target);
			else if(option_debug_jobs_dot) /* debug dump all jobs as dot */
				node_debug_dump_jobs_dot(context.graph, context.target);
			else if(option_dry)
			{
			}
			else
			{
				/* run build or clean */
				if(option_clean)
				{
					event_begin(0, "clean", NULL);
					build_error = context_build_clean(&context);
					event_end(0, "end", NULL);
				}
				else
				{
					event_begin(0, "build", NULL);
					build_error = context_build_make(&context);
					event_end(0, "build", NULL);
					report_done = 1;
				}
			}
		}
	}		

	/* save cache (thread?) */
	if(option_no_cache == 0 && setup_error == 0)
	{
		event_begin(0, "cache save", cache_filename);
		cache_save(cache_filename, context.graph);
		event_end(0, "cache save", NULL);
	}
	
	/* clean up */
	mem_destroy(context.graphheap);
	free(context.joblist);
	cache_free(context.cache);

	/* print final report and return */
	if(setup_error)
	{
		/* no error message on setup error, it reports fine itself */
		return setup_error;
	}
	else if(build_error)
		printf("%s: error: a build step failed\n", session.name);
	else if(report_done)
	{
		if(context.num_jobs == 0)
			printf("%s: targets are up to date already\n", session.name);
		else
		{
			time_t s = time(0x0) - starttime;
			if(s <= 1)
				printf("%s: done\n", session.name);
			else
				printf("%s: done (%d:%.2d)\n", session.name, (int)(s/60), (int)(s%60));
		}
	}

	return build_error;
}
Ejemplo n.º 12
0
/// Create and Initialize a memory pool.
/// \param[in]     pool_def      memory pool definition referenced with \ref osPool.
/// \return memory pool ID for reference by other functions or NULL in case of error.
/// \note MUST REMAIN UNCHANGED: \b osPoolCreate shall be consistent in every CMSIS-RTOS.
osPoolId osPoolCreate (const osPoolDef_t *pool_def)
{
	return mem_create(pool_def->pool_sz, pool_def->item_sz);
}
Ejemplo n.º 13
0
struct si_work_group_t *si_work_group_create(unsigned int work_group_id, 
	struct si_ndrange_t *ndrange)
{
	struct si_bin_enc_user_element_t *user_elements;
	struct si_wavefront_t *wavefront;
	struct si_work_group_t *work_group;
	struct si_work_item_t *work_item;

	/*MIAOW Start */
	struct opencl_si_kernel_t *kernel = ndrange->kernel;
	unsigned long long mask = 0x00000000;
	/*MIAOW Stop */

	int i;
	int lid;
	int lidx, lidy, lidz;
	int tid;
	int user_element_count;
	int wavefront_id;
	int wavefront_offset;
	int work_item_id;
	int work_item_gidx_start;
	int work_item_gidy_start;
	int work_item_gidz_start;


	/*MIAOW start*/
	//UNIT TEST
	
	char unit_test_input_buf[150000];
	char *tok = NULL;
	char *config_read_result = NULL;
	char vreg_str[64][2500];
	char sreg_str[2500];
	int num_of_threads = 0;

	FILE* unit_test_config = fopen("unit_test_config.txt", "r");
	if (unit_test_config != 0)
	{

		ndrange->local_size3[2] = 1;
		ndrange->local_size3[1] = 1;
		ndrange->global_size3[2] = 1;
		ndrange->global_size3[1] = 1;
		
		config_read_result = fgets(unit_test_input_buf, 150000, unit_test_config);
		if(config_read_result != NULL)
		{
			tok = strtok(unit_test_input_buf, ";"); //WG count
			ndrange->group_count = atoi(tok);

			tok = strtok(NULL, ";"); //total number of threads
			num_of_threads = atoi(tok);

			ndrange->global_size = atoi(tok);
			ndrange->global_size3[0] = atoi(tok);
			ndrange->local_size3[0] = atoi(tok);
			ndrange->local_size = atoi(tok);

		}
	}

	//WorkGroup count and thread count
	//fprintf(config,"%d;%d;\n", ndrange->group_count, ndrange->global_size);

#ifdef MIAOW_DEBUG
	fflush(config);
#endif
	/*MIAOW stop*/

	/* Number of in work-items in work-group */
	unsigned int work_items_per_group = ndrange->local_size3[0] * 
		ndrange->local_size3[1] * ndrange->local_size3[2];
	assert(work_items_per_group > 0);

	/* Number of wavefronts in work-group */
	unsigned int wavefronts_per_group = (work_items_per_group + 
		(si_emu_wavefront_size - 1)) / si_emu_wavefront_size;
	assert(wavefronts_per_group > 0);

	/* Initialize */
	work_group = xcalloc(1, sizeof(struct si_work_group_t));
	work_group->id = work_group_id;
	work_group->ndrange = ndrange;

	/* Create LDS */
	work_group->lds_module = mem_create();
	work_group->lds_module->safe = 0;

	/* Allocate pointers for work-items (will actually be created when
	 * wavefronts are created) */
	work_group->work_items = xcalloc(si_emu_wavefront_size * 
		wavefronts_per_group, sizeof(void *));
	work_group->wavefronts = xcalloc(wavefronts_per_group, sizeof(void *));
	work_group->wavefront_count = wavefronts_per_group;

	/* Allocate wavefronts and work-items */
	SI_FOREACH_WAVEFRONT_IN_WORK_GROUP(work_group, wavefront_id)
	{
		work_group->wavefronts[wavefront_id] = si_wavefront_create(
			work_group->id * wavefronts_per_group + wavefront_id,
			work_group);

		wavefront = work_group->wavefronts[wavefront_id];

		SI_FOREACH_WORK_ITEM_IN_WAVEFRONT(wavefront, work_item_id)
		{
			wavefront_offset = wavefront_id * si_emu_wavefront_size;

			work_group->work_items[wavefront_offset+work_item_id] = 
				wavefront->work_items[work_item_id];
			work_group->work_items[wavefront_offset+work_item_id]->
				work_group = work_group;
		}