Example #1
0
void macpci_state::pippin(machine_config &config)
{
	/* basic machine hardware */
	PPC603(config, m_maincpu, 66000000);
	m_maincpu->set_addrmap(AS_PROGRAM, &macpci_state::pippin_mem);

	/* video hardware */
	screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_RASTER));
	screen.set_refresh_hz(60);
	screen.set_vblank_time(ATTOSECONDS_IN_USEC(2500)); /* not accurate */
	screen.set_size(640, 480);
	screen.set_visarea(0, 640-1, 0, 480-1);
	screen.set_screen_update(FUNC(macpci_state::screen_update_pippin));
	screen.set_palette("palette");

	palette_device &palette(PALETTE(config, "palette", 2));
	palette.set_init("palette", FUNC(palette_device::palette_init_monochrome));

	/* sound hardware */
	SPEAKER(config, "lspeaker").front_left();
	SPEAKER(config, "rspeaker").front_right();

	cdda_device &cdda(CDDA(config, "cdda"));
	cdda.add_route(0, "lspeaker", 1.00);
	cdda.add_route(1, "rspeaker", 1.00);

	cdrom_image_device &cdrom(CDROM(config, "cdrom", 0));
	cdrom.set_interface("pippin_cdrom");
	SOFTWARE_LIST(config, "cd_list").set_type("pippin", SOFTWARE_LIST_ORIGINAL_SYSTEM);

	RAM(config, m_ram);
	m_ram->set_default_size("32M");

	VIA6522(config, m_via1, C7M/10);
	m_via1->readpa_handler().set(FUNC(macpci_state::mac_via_in_a));
	m_via1->readpb_handler().set(FUNC(macpci_state::mac_via_in_b));
	m_via1->writepa_handler().set(FUNC(macpci_state::mac_via_out_a));
	m_via1->writepb_handler().set(FUNC(macpci_state::mac_via_out_b));
	m_via1->cb2_handler().set(FUNC(macpci_state::mac_adb_via_out_cb2));
	m_via1->irq_handler().set(FUNC(macpci_state::mac_via_irq));

	//scc8530_t &scc(SCC8530(config, "scc", C7M));
	//scc.intrq_callback().set(FUNC(macpci_state::set_scc_interrupt));
	CUDA(config, m_cuda, 0);
	m_cuda->set_type(CUDA_341S0060);
	m_cuda->reset_callback().set(FUNC(macpci_state::cuda_reset_w));
	m_cuda->linechange_callback().set(FUNC(macpci_state::cuda_adb_linechange_w));
	m_cuda->via_clock_callback().set(m_via1, FUNC(via6522_device::write_cb1));
	m_cuda->via_data_callback().set(m_via1, FUNC(via6522_device::write_cb2));
	config.m_perfect_cpu_quantum = subtag("maincpu");
}
Example #2
0
// Process
bool imageNet::Process()
{
	void* bindBuffers[] = { mInputCUDA, mOutputs[0].CUDA };	
	cudaStream_t stream = GetStream();

	if( !stream )
	{
		if( !mContext->execute(1, bindBuffers) )
		{
			printf(LOG_TRT "imageNet::Process() -- failed to execute TensorRT network\n");
			return false;
		}
	}
	else
	{
		//printf("%s stream %p\n", deviceTypeToStr(GetDevice()), GetStream());

		//CUDA(cudaEventRecord(mEvents[0], stream));
		
		// queue the inference processing kernels
		const bool result = mContext->enqueue(1, bindBuffers, stream, NULL);

		//CUDA(cudaEventRecord(mEvents[1], stream));
		//CUDA(cudaEventSynchronize(mEvents[1]));
		CUDA(cudaStreamSynchronize(stream));

		if( !result )
		{
			printf(LOG_TRT "imageNet::Process() -- failed to enqueue TensorRT network\n");
			return false;
		}	
	}

	//CUDA(cudaDeviceSynchronize());
	PROFILER_REPORT();

	return true;
}
// main entry point
int main( int argc, char** argv )
{
	printf("imagenet-console\n  args (%i):  ", argc);
	
	for( int i=0; i < argc; i++ )
		printf("%i [%s]  ", i, argv[i]);
		
	printf("\n\n");
	
	
	// retrieve filename argument
	if( argc < 2 )
	{
		printf("imagenet-console:   input image filename required\n");
		return 0;
	}
	
	const char* imgFilename = argv[1];
	

	// create imageNet
	imageNet* net = imageNet::Create(argc, argv);

	if( !net )
	{
		printf("imagenet-console:   failed to initialize imageNet\n");
		return 0;
	}
	
	net->EnableProfiler();
	
	// load image from file on disk
	float* imgCPU    = NULL;
	float* imgCUDA   = NULL;
	int    imgWidth  = 0;
	int    imgHeight = 0;
		
	if( !loadImageRGBA(imgFilename, (float4**)&imgCPU, (float4**)&imgCUDA, &imgWidth, &imgHeight) )
	{
		printf("failed to load image '%s'\n", imgFilename);
		return 0;
	}

	float confidence = 0.0f;
	
	// classify image
	const int img_class = net->Classify(imgCUDA, imgWidth, imgHeight, &confidence);
	
	if( img_class >= 0 )
	{
		printf("imagenet-console:  '%s' -> %2.5f%% class #%i (%s)\n", imgFilename, confidence * 100.0f, img_class, net->GetClassDesc(img_class));
	
		if( argc > 2 )
		{
			const char* outputFilename = argv[2];
			
			// overlay the classification on the image
			cudaFont* font = cudaFont::Create();
			
			if( font != NULL )
			{
				char str[512];
				sprintf(str, "%2.3f%% %s", confidence * 100.0f, net->GetClassDesc(img_class));

				const int overlay_x = 10;
				const int overlay_y = 10;
				const int px_offset = overlay_y * imgWidth * 4 + overlay_x * 4;

				// if the image has a white background, use black text (otherwise, white)
				const float white_cutoff = 225.0f;
				bool white_background = false;

				if( imgCPU[px_offset] > white_cutoff && imgCPU[px_offset + 1] > white_cutoff && imgCPU[px_offset + 2] > white_cutoff )
					white_background = true;

				// overlay the text on the image
				font->RenderOverlay((float4*)imgCUDA, (float4*)imgCUDA, imgWidth, imgHeight, (const char*)str, 10, 10,
								white_background ? make_float4(0.0f, 0.0f, 0.0f, 255.0f) : make_float4(255.0f, 255.0f, 255.0f, 255.0f));
			}
			
			printf("imagenet-console:  attempting to save output image to '%s'\n", outputFilename);
			
			if( !saveImageRGBA(outputFilename, (float4*)imgCPU, imgWidth, imgHeight) )
				printf("imagenet-console:  failed to save output image to '%s'\n", outputFilename);
			else
				printf("imagenet-console:  completed saving '%s'\n", outputFilename);
		}
	}
	else
		printf("imagenet-console:  failed to classify '%s'  (result=%i)\n", imgFilename, img_class);
	
	printf("\nshutting down...\n");
	CUDA(cudaFreeHost(imgCPU));
	delete net;
	return 0;
}