int CKXDialog::on_command(int wParam, int lParam)
{
	switch(wParam)
	{
		case IDg_INFO:
		    manager->launch(LAUNCH_INFO);
                    return 1;
                case IDg_MINI:
                    SendMessage(WM_SYSCOMMAND,SC_MINIMIZE);
                    return 1;
                case IDg_CARDNAME:
                    {
                     manager->change_device(-2,this);
                     return 1;
                    }
                case IDg_SAVE_SETTINGS:
                    manager->save_settings(SETTINGS_GUI,NULL,get_flag()|KX_SAVED_NO_VERSION|KX_SAVED_NO_CARDNAME);
                    select_device();
                    return 1;
                case IDg_LOAD_SETTINGS:
                    manager->restore_settings(SETTINGS_GUI,NULL,get_flag()|KX_SAVED_NO_VERSION|KX_SAVED_NO_CARDNAME);
                    select_device();
                    return 1;
	}
	return kDialog::on_command(wParam,lParam);
}
Beispiel #2
0
void chose_physical_device()
{
    uint32_t deviceCount = 0;
    vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr);

    if(deviceCount == 0)
    {
        cerr<<"no device with vulkan support found"<<endl;
        return;
    }

    std::vector<VkPhysicalDevice> devices(deviceCount);
    vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data());

    if(!select_device(devices, physical_device))
    {
        cerr<<"no suitable device found"<<endl;
        return;
    }

    VkPhysicalDeviceProperties deviceProperties;
    vkGetPhysicalDeviceProperties(physical_device, &deviceProperties);

    cout << "chosen device:" << deviceProperties.deviceName << endl;
}
static void init(struct fmt_main *self) {
	int 	i ;

	//Prepare OpenCL environment.
	opencl_preinit();

	///Allocate memory
	key_host = mem_calloc(self -> params.max_keys_per_crypt, sizeof(*key_host)) ;
	dcc_hash_host = (cl_uint*)mem_alloc(4 * sizeof(cl_uint) * MAX_KEYS_PER_CRYPT) ;
	dcc2_hash_host = (cl_uint*)mem_alloc(4 * sizeof(cl_uint) * MAX_KEYS_PER_CRYPT) ;
	hmac_sha1_out  = (cl_uint*)mem_alloc(5 * sizeof(cl_uint) * MAX_KEYS_PER_CRYPT) ;

	memset(dcc_hash_host, 0, 4 * sizeof(cl_uint) * MAX_KEYS_PER_CRYPT) ;
	memset(dcc2_hash_host, 0, 4 * sizeof(cl_uint) * MAX_KEYS_PER_CRYPT) ;

	/* Read LWS/GWS prefs from config or environment */
	opencl_get_user_preferences(FORMAT_LABEL);

	for( i=0; i < get_number_of_devices_in_use(); i++)
		select_device(gpu_device_list[i], self) ;

	dcc2_warning() ;

	if (pers_opts.target_enc == UTF_8) {
		self->params.plaintext_length *= 3;
		if (self->params.plaintext_length > 125)
			self->params.plaintext_length = 125;
	}
}
 void KokkosDeviceWrapperNode<Kokkos::Cuda>::init(int NumTeams, int NumThreads, int Device) {
   if(!Kokkos::Cuda::host_mirror_device_type::is_initialized())
     Kokkos::Cuda::host_mirror_device_type::initialize(NumTeams*NumThreads);
   Kokkos::Cuda::SelectDevice select_device(Device);
   if(!Kokkos::Cuda::is_initialized())
     Kokkos::Cuda::initialize(select_device);
 }
Beispiel #5
0
void *wave_open(int srate, const char *device)
{
	PaError err;

	pa_stream = NULL;
	wave_samplerate = srate;
	mInCallbackFinishedState = false;
	init_buffer();

	// PortAudio sound output library
	err = Pa_Initialize();
	pa_init_err = err;
	if (err != paNoError)
		return NULL;

	static int once = 0;

	if (!once) {
		if (!select_device(device))
			return NULL;
		once = 1;
	}

	return (void *)1;
}
Beispiel #6
0
int main(int argc, char **argv)
{
 long long int size = 110503; // a prime number
 int numVecs = 4;
 int threads=1;
 int device = 0;
 int numa=1;
 int test=-1;
 int type=-1;
 char* filename = NULL;
 bool binaryfile = false;

 for(int i=0;i<argc;i++)
 {
  if((strcmp(argv[i],"-d")==0)) {device=atoi(argv[++i]); continue;}
  if((strcmp(argv[i],"-s")==0)) {size=atoi(argv[++i]); continue;}
  if((strcmp(argv[i],"-v")==0)) {numVecs=atoi(argv[++i]); continue;}
  if((strcmp(argv[i],"--threads")==0)) {threads=atoi(argv[++i]); continue;}
  if((strcmp(argv[i],"--numa")==0)) {numa=atoi(argv[++i]); continue;}
  if((strcmp(argv[i],"--test")==0)) {test=atoi(argv[++i]); continue;}
  if((strcmp(argv[i],"--type")==0)) {type=atoi(argv[++i]); continue;}
  if((strcmp(argv[i],"-f")==0)) {filename = argv[++i]; continue;}
  if((strcmp(argv[i],"-fb")==0)) {filename = argv[++i]; binaryfile = true; continue;}
 }


 KokkosArrayCUDA(
   KokkosArray::Cuda::SelectDevice select_device(device);
   KokkosArray::Cuda::initialize( select_device );
 )
Beispiel #7
0
//--------------------------------------------------------------------------
static const char *set_idp_options(const char *keyword, int, const void *)
{
  if ( keyword != NULL )
    return IDPOPT_BADKEY;
  select_device(IORESP_PORT|IORESP_INT);
  return IDPOPT_OK;
}
Beispiel #8
0
W2XConv *
w2xconv_init(enum W2XConvGPUMode gpu,
             int nJob,
	     int enable_log)
{
	global_init();

	int proc_idx = select_device(gpu);
	return w2xconv_init_with_processor(proc_idx, nJob, enable_log);
}
Beispiel #9
0
 void read(u16 address)
 {
     assert(state::idle == status);
     if (state::idle != status)
         return;
     
     select_device(select::aux);
     regs.control.rxtx = 1;
     status = state::reading_sending_address;
     regs.data = (address & (~0x8000)); // msb = 0 : read (convention with aux software)
 }
Beispiel #10
0
        void write(u16 address, u16 word)
        {
            assert(state::idle == status);
            if (state::idle != status)
                return;

            select_device(select::aux);
            regs.control.rxtx = 1;
            status = state::writing_sending_address;
            data = word;
            regs.data = (address | 0x8000); // msb = 1 : write (convention with aux software)
        }
Beispiel #11
0
void xyzzy_get_keys()
{
	int i;
	FILE *fp = NULL;
	
	bool xyzzy_device = select_device();
	if (xyzzy_device)
	{
		char path[16] = {0};
		sprintf(path, "%s:/keys.txt", device == 1 ? "sd" : "usb");
		
		fp = fopen(path, "w");
		if (!fp)
		{
			printf("\n\t- Unable to open keys.txt for writing.");
			printf("\n\t- Sorry, not writing keys to %s.", device == 1 ? "card" : "USB device");
			if (device == 1) Close_SD();
			if (device == 2) Close_USB();
			sleep(2);
		}
	}
	
	resetscreen();
	printheadline();
	printf("Getting keys...\n\n");
	
	/* This is where the magic begins */
	/* Access to the SEEPROM will be disabled in we're running under vWii */
	print_all_keys(stdout, vWii);
	
	if (fp)
	{
		print_all_keys(fp, vWii);
		
		/* This will create a hexdump of the device.cert in the selected device */
		char devcert[0x200];
		memset(devcert, 42, 0x200);
		i = ES_GetDeviceCert((u8*)devcert);
		if (i)
		{
			printf("\n\nES_GetDeviceCert returned %d.\n\n", i);
		} else {
			fprintf(fp, "\nDevice cert:\n");
			hexdump(fp, devcert, 0x180);
		}
		
		fclose(fp);
		
		if (device == 1) Close_SD();
		if (device == 2) Close_USB();
	}
}
Beispiel #12
0
void* wave_open(const char* the_api)
{
  ENTER("wave_open");
  static int once=0;

  // TBD: the_api (e.g. "alsa") is not used at the moment
  // select_device is called once
  if (!once)
    {
      select_device("alsa");
      once=1;
    }
  return((void*)1);
}
void CMidiRouterDlg::init()
{
	generic_init("midi");

	char tmp_str[256];

        if(!mf.get_profile("midi","reset_button",tmp_str,sizeof(tmp_str)))
        {
         gui_create_button(this,&b_reset,IDM_RESET,tmp_str,mf);
         b_reset.ShowWindow(SW_SHOW);
        }

	CreateParserInterface();

        select_device();
}
Beispiel #14
0
void test_cuda_fixture( comm::Machine machine ,
                        size_t nx , size_t ny , size_t nz )
{
  const size_t comm_rank = comm::rank( machine );
  const size_t comm_size = comm::size( machine );
  const size_t dev_count = Kokkos::Cuda::detect_device_count();
  const size_t dev_rank =
    dev_count && dev_count <= comm_size ? comm_rank % dev_count : 0 ;
  const size_t gang_count = 0 ;

  Kokkos::HostSpace::execution_space::initialize();
  Kokkos::Cuda::SelectDevice select_device( dev_rank );
  Kokkos::Cuda::initialize( select_device );
  test_box_fixture<Kokkos::Cuda>( machine , gang_count , nx , ny , nz );
  Kokkos::Cuda::finalize();
  Kokkos::HostSpace::execution_space::finalize();
}
static void
bt_settings_page_interaction_controller_set_property (GObject * const object,
    const guint property_id, const GValue * const value,
    GParamSpec * const pspec)
{
  BtSettingsPageInteractionController *self =
      BT_SETTINGS_PAGE_INTERACTION_CONTROLLER (object);
  return_if_disposed ();
  switch (property_id) {
    case PROP_DEVICE:
      select_device (self, BTIC_DEVICE (g_value_get_object (value)));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
  }
}
Beispiel #16
0
void test_cuda_implicit( comm::Machine machine , 
                         size_t elem_count_begin ,
                         size_t elem_count_end ,
                         size_t count_run )
{
  const size_t comm_rank = comm::rank( machine );
  const size_t comm_size = comm::size( machine );
  const size_t dev_count = Kokkos::Cuda::detect_device_count();
  const size_t dev_rank =
    dev_count && dev_count <= comm_size ? comm_rank % dev_count : 0 ;
  const size_t gang_count = 0 ;

  Kokkos::HostSpace::execution_space::initialize();
  Kokkos::Cuda::SelectDevice select_device( dev_rank );
  Kokkos::Cuda::initialize( select_device );
  HybridFEM::Implicit::driver<double,Kokkos::Cuda>( "Cuda" , machine , gang_count , elem_count_begin , elem_count_end , count_run );
  Kokkos::Cuda::finalize();
  Kokkos::HostSpace::execution_space::finalize();
}
Beispiel #17
0
        void init(u8 spi_int_priority, bool fast_spi_irq, u8 aux_int_priority, bool fast_aux_irq)
        {
            // deselect all devices
            select_device(select::none);

            regs.master_control.spi_1_clock_enable = true;
            regs.master_control.spi_1_pin_control = true;
            
            regs.global_control.enable = true;
            regs.global_control.reset = true; // reset must be done after controller is enabled
            regs.global_control.reset = false;

            // Aux controller supports up to 16.6 mbps. If the other devices cannot go as high, we may need to reprogram the rate for each transfer depending on the target
            //regs.control.rate = compute_rate(16100000); // effective rate will be 12.5Mbps, this divider is applied directly on the h_clock, so it's not very precise for high rates
            regs.control.rate = compute_rate(8000000);
            regs.control.master = true;
            regs.control.bitnum = 0xF; // 16 bits
            regs.control.shift_off = false; // enable the clock output
            regs.control.thr = 0; // select no threshold (interrupt as soon as 1 entry in FIFO)
            regs.control.mode = 1; // clock starts low, data sampled on falling edge
            regs.control.lsb_first = false; // send most significant bit first
            regs.control.bhalt = false; // don't use the busy signal
            regs.control.unidir = true; // bidirectional
            regs.control.rxtx = 1; // output at all times, we don't mux the pin

            regs.frame_count = 0; // single frame sent, no block transfers

            regs.interrupt.intthr = true;
            regs.interrupt.inteot = true;

            regs.timer_control.mode = 0;
            regs.timer_control.pirqe = 1;
            regs.timer_control.tirqe = 0;

            // register the SPI interrupt handler - we don't need it yet, our only spi device is the aux controller which sends us an interrupt on its own. for the IMU, this may change.
            //get_int_ctrl().install_service_routine(interrupt::id::spi_1, spi_int_priority, fast_spi_irq, interrupt::trigger::high_level, static_spi_isr);
            //get_int_ctrl().enable_interrupt(interrupt::id::spi_1);

            // register the auxiliary controller interrupt handler (tells us when data is ready)
            get_int_ctrl().install_service_routine(interrupt::id::aux_ctrl_spi, aux_int_priority, fast_aux_irq, interrupt::trigger::positive_edge, static_aux_isr);
            get_int_ctrl().enable_interrupt(interrupt::id::aux_ctrl_spi);
        }
Beispiel #18
0
void test_cuda_nonlinear_quadratic( comm::Machine machine , 
                                    size_t elem_count_begin ,
                                    size_t elem_count_end ,
                                    size_t count_run )
{
  const size_t comm_rank = comm::rank( machine );
  const size_t comm_size = comm::size( machine );
  const size_t dev_count = Kokkos::Cuda::detect_device_count();
  const size_t dev_rank =
    dev_count && dev_count <= comm_size ? comm_rank % dev_count : 0 ;
  const size_t gang_count = 0 ;

  Kokkos::HostSpace::execution_space::initialize();
  Kokkos::Cuda::SelectDevice select_device( dev_rank );
  Kokkos::Cuda::initialize( select_device );

  typedef Kokkos::Cuda device ;
  typedef FixtureElementHex27 hex27 ;
  HybridFEM::Nonlinear::driver<double,device,hex27>( "Cuda" , machine , gang_count , elem_count_begin , elem_count_end , count_run );
  Kokkos::Cuda::finalize();
  Kokkos::HostSpace::execution_space::finalize();
}
Beispiel #19
0
static int connect_device(const char *file)
{
    int result;

    fprintf(stdout, TTY_NONE "Connect \"%s\"...", file);

    if ((result = open_serial_port(file)))
        return result;

    if ((result = reset_device(1)))
        return result;

    if ((result = handshake_device()))
        return result;

    device_buffer[0] = 0x00;
    if ((result = device_request(1)))
        return result;

    if ((result = device_response(13)))
        return result;

    device_version = device_buffer[1];
    device_erase_command = device_buffer[8];
    fprintf(stdout, TTY_NONE "V%1X.%1X...", device_version >> 4, device_version & 0x0F);

    device_buffer[0] = 0x02;
    if ((result = device_request(1)))
        return result;

    if ((result = device_response(3)))
        return result;

    if ((result = select_device(device_buffer[1] << 8 | device_buffer[2])))
        return result;

    return DONE;
}
Beispiel #20
0
int main(int argc, char *argv[])
{
    if ((argc == 2) && !strcmp(argv[1], "--list-devices"))
        return print_devices() ? EXIT_SUCCESS : EXIT_FAILURE;

    if ((argc == 3) && !strcmp(argv[1], "--use-device"))
    {
        try
        {
            cl::Device device; // The device is selected by the user
            if (!select_device(argv[2], device)) return EXIT_FAILURE;

            try
            {
                print_info("Initializing graphical user interface");
                auto window = display::initialize("Voxel Renderer");

                print_info("Selecting preferred interop interface");
                interop::initialize(device, window->getSystemHandle());
                print_info("Scheduler ready, interop is available");
                print_info("Loading world from user-provided file");
                print_warning("Not implemented yet");
                World world;
                print_info("World ready");

                try
                {
                    display::run(window, world);
                    display::finalize(window);
                }
                catch (const cl::Error &e)
                {
                    print_exception("OpenCL runtime error", e);
                    return EXIT_FAILURE; // Perhaps driver bug?
                }
            }
            catch (const cl::Error &e)
            {
                print_exception("OpenCL initialization failure", e);
                return EXIT_FAILURE; // Selected device unsupported?
            }
        }
        catch (const std::exception &e)
        {
            print_exception("A fatal error occurred", e);
            return EXIT_FAILURE; // Not an OpenCL error..
        }
        catch (...)
        {
            print_error("Caught unhandled exception");
            return EXIT_FAILURE; // Fatal error here..
        }

        print_info("Exiting");
        return EXIT_SUCCESS;
    }

    printf("Usage:\n\n\t%s %s [name]", argv[0], "--use-device");
    printf(      "\n\t%s %s\n", argv[0], "--list-devices");
    printf("\nThis software requires OpenCL 1.2.\n");
    return EXIT_FAILURE; // Argument parsing error
}
Beispiel #21
0
/*
 * If writing to a file, check to see if it exists
 */
void do_hardcopy(const GProject *gp)
{
    Quark *project = gproject_get_top(gp);
    GraceApp *gapp = gapp_from_quark(project);
    RunTime *rt;
    Canvas *canvas;
    char fname[GR_MAXPATHLEN];
    view v;
    double vx, vy;
    int truncated_out, res;
    FILE *prstream;
    
    if (!gapp) {
        return;
    }
    
    rt = gapp->rt;
    canvas = grace_get_canvas(gapp->grace);
    
    if (get_ptofile(gapp)) {
        if (string_is_empty(rt->print_file)) {
            Device_entry *dev = get_device_props(canvas, rt->hdevice);
            sprintf(rt->print_file, "%s.%s",
                QIDSTR(project), dev->fext);
        }
        strcpy(fname, rt->print_file);
        prstream = gapp_openw(gapp, fname);
    } else {
        strcpy(fname, "gappXXXXXX");
        prstream = gapp_tmpfile(fname);
    }
    
    if (prstream == NULL) {
        return;
    }
    
    canvas_set_prstream(canvas, prstream); 
    
    select_device(canvas, rt->hdevice);
    
    res = gproject_render(gp);
    
    gapp_close(prstream);
    
    if (res != RETURN_SUCCESS) {
        return;
    }
    
    get_bbox(canvas, BBOX_TYPE_GLOB, &v);
    project_get_viewport(project, &vx, &vy);
    if (v.xv1 < 0.0 - VP_EPSILON || v.xv2 > vx + VP_EPSILON ||
        v.yv1 < 0.0 - VP_EPSILON || v.yv2 > vy + VP_EPSILON) {
        truncated_out = TRUE;
    } else {
        truncated_out = FALSE;
    }
    
    if (get_ptofile(gapp) == FALSE) {
        if (truncated_out == FALSE ||
            yesno("Printout is truncated. Continue?", NULL, NULL, NULL)) {
            gapp_print(gapp, fname);
#ifndef PRINT_CMD_UNLINKS
            remove(fname);
#endif
        }
    } else {
        if (truncated_out == TRUE) {
            errmsg("Output is truncated - tune device dimensions");
        }
    }
}
Beispiel #22
0
 void reset()
 {
     // deselect all devices
     select_device(select::none);
     status = state::idle;
 }
Beispiel #23
0
/****************************************************************************
* Main
****************************************************************************/
int main () 
{
	// Setup defaults (if no config is found)
	memset(&swissSettings, 0 , sizeof(SwissSettings));
	
	void *fb;
	fb = Initialise();
	if(!fb) {
		return -1;
	}

	// Sane defaults
	refreshSRAM();
	swissSettings.debugUSB = 1;
	swissSettings.gameVMode = 0;	// Auto video mode
	swissSettings.exiSpeed = 1;		// 32MHz
	swissSettings.uiVMode = 0; 		// Auto UI mode
	swissSettings.enableFileManagement = 0;

	config_copy_swiss_settings(&swissSettings);
	needsDeviceChange = 1;
	needsRefresh = 1;
	

	//debugging stuff
	if(swissSettings.debugUSB) {
		if(usb_isgeckoalive(1)) {
			usb_flush(1);
		}
		print_gecko("Arena Size: %iKb\r\n",(SYS_GetArena1Hi()-SYS_GetArena1Lo())/1024);
		print_gecko("DVD Drive Present? %s\r\n",swissSettings.hasDVDDrive?"Yes":"No");
		print_gecko("GIT Commit: %s\r\n", GITREVISION);
		print_gecko("GIT Revision: %s\r\n", GITVERSION);
	}
	
	// Detect devices
	populateDeviceAvailability();
	
	curDevice = -1;
	// Are we working with a Wiikey Fusion?
	if(__wkfSpiReadId() != 0 && __wkfSpiReadId() != 0xFFFFFFFF) {
		print_gecko("Detected Wiikey Fusion with SPI Flash ID: %08X\r\n",__wkfSpiReadId());

		// Set real device back
		curDevice = WKF;

		// SlotB hack
		trySlotB();
	}
	else {
		deviceHandler_setStatEnabled(0);
		// Try to init SD cards here and load config
		deviceHandler_initial = &initial_SD0;
		deviceHandler_init		=  deviceHandler_FAT_init;
		deviceHandler_deinit	=  deviceHandler_FAT_deinit;
		if(deviceHandler_init(deviceHandler_initial)) {
			print_gecko("Detected SDGecko in Slot A\r\n");
			load_auto_dol();
			curDevice = SD_CARD;
		}
		else {
			deviceHandler_deinit(deviceHandler_initial);
			deviceHandler_initial = &initial_SD1;
			if(deviceHandler_init(deviceHandler_initial)) {
				print_gecko("Detected SDGecko in Slot B\r\n");
				load_auto_dol();
				curDevice = SD_CARD;
			}
		}
		deviceHandler_setStatEnabled(1);
	}
	
	// If no device has been selected yet to browse ..
	if(curDevice < 0) {
		print_gecko("No default boot device detected, trying DVD!\r\n");
		// Do we have a DVD drive with a ready medium we can perhaps browse then?
		u8 driveReallyExists[8];
		drive_version(&driveReallyExists[0]);
		if(*(u32*)&driveReallyExists[0]) {
			dvd_read_id();
			if(!dvd_get_error()) {
				print_gecko("DVD Medium is up, using it as default device\r\n");
				curDevice = DVD_DISC;
				
				// If we have a GameCube (single image) bootable disc, show the banner screen here
				dvdDiscTypeInt = gettype_disc();
				if(dvdDiscTypeInt == GAMECUBE_DISC) {
					select_device(1);
					// Setup curFile and load it
					memset(&curFile, 0, sizeof(file_handle));
					strcpy(&curFile.name[0], "game.gcm");
					curFile.size = DISC_SIZE;
					curFile.fileAttrib = IS_FILE;
					populate_meta(&curFile);
					load_file();
					curDevice = -1;
					deviceHandler_initial = NULL;
				}
			}
		}
	}
	if(curDevice) {
		needsDeviceChange = 0;
		select_device(1); // to setup deviceHandler_ ptrs
		load_config(forceSlot);
	}

	// Start up the BBA if it exists
	init_network_thread();
	init_httpd_thread();
	
	// DVD Motor off
	if(swissSettings.stopMotor && swissSettings.hasDVDDrive) {
		dvd_motor_off();
	}

	// Swiss video mode force
	GXRModeObj *forcedMode = getModeFromSwissSetting(swissSettings.uiVMode);
	
	if((forcedMode != NULL) && (forcedMode != vmode)) {
		initialise_video(forcedMode);
		vmode = forcedMode;
	}

	while(1) {
		main_loop();
	}
	return 0;
}
Beispiel #24
0
void main_loop()
{ 	
	while(PAD_ButtonsHeld(0) & PAD_BUTTON_A) { VIDEO_WaitVSync (); }
	// We don't care if a subsequent device is "default"
	if(needsDeviceChange) {
		free_files();
		if(deviceHandler_deinit) {
			deviceHandler_deinit(deviceHandler_initial);
		}
		if (forceSlot) {
			deviceHandler_FAT_deinit(&initial_SD1);
		}
		curDevice = -1;
		needsDeviceChange = 0;
		deviceHandler_initial = NULL;
		needsRefresh = 1;
		curMenuLocation = ON_FILLIST;
		select_device(0);
		if (curDevice == WKF)  {
			trySlotB();
		}
		curMenuLocation = ON_OPTIONS;
	}
	
	if(deviceHandler_initial) {
		// If the user selected a device, make sure it's ready before we browse the filesystem
		deviceHandler_deinit( deviceHandler_initial );
		sdgecko_setSpeed(EXI_SPEED32MHZ);
		if(!deviceHandler_init( deviceHandler_initial )) {
			if(((deviceHandler_initial->name[0] == 's')&&(deviceHandler_initial->name[1] == 'd'))||(deviceHandler_initial->name[0] == 'i')) {
				print_gecko("SD/IDE-EXI Device Failed to initialize @ 32MHz!\r\nTrying again once @ 16MHz...\r\n");
				sdgecko_setSpeed(EXI_SPEED16MHZ);
				if(!deviceHandler_init(deviceHandler_initial)) {
				// Try the alternate slot for SDGecko or IDE-EXI
					if(deviceHandler_initial->name[0] == 's')
						deviceHandler_initial = (deviceHandler_initial == &initial_SD0) ?
												&initial_SD1:&initial_SD0;
					else
						deviceHandler_initial = (deviceHandler_initial == &initial_IDE0) ?
												&initial_IDE1:&initial_IDE0;
					memcpy(&curFile, deviceHandler_initial, sizeof(file_handle));
				}
				print_gecko("Trying alternate slot @ 32MHz...\r\n");
				sdgecko_setSpeed(EXI_SPEED32MHZ);
				if(!deviceHandler_init( deviceHandler_initial )) {
					print_gecko("Alternate slot failed once @ 16MHz... \r\n");
					sdgecko_setSpeed(EXI_SPEED16MHZ);
					if(!deviceHandler_init( deviceHandler_initial )) {
						print_gecko("Both slots failed twice\r\n");
						needsDeviceChange = 1;
						return;
					}
				}
			}
		}
		if(curDevice==SD_CARD || curDevice==WKF || curDevice==IDEEXI) { 
			load_config(forceSlot);
		}
	}
	else {
		curMenuLocation=ON_OPTIONS;
	}
	// If a previously undetected device has been successfully init'd, mark it as available from now on
	if(!deviceHandler_getDeviceAvailable(curDevice)) {
		deviceHandler_setDeviceAvailable(curDevice, 1);
	}
  
	while(1) {
		if(deviceHandler_initial && needsRefresh) {
			curMenuLocation=ON_OPTIONS;
			free_files();
			curSelection=0; files=0; curMenuSelection=0;
			// Read the directory/device TOC
			if(allFiles){ free(allFiles); allFiles = NULL; }
			print_gecko("Reading directory: %s\r\n",curFile.name);
			files = deviceHandler_readDir(&curFile, &allFiles, -1);
			memcpy(&curDir, &curFile, sizeof(file_handle));
			sortFiles(allFiles, files);
			print_gecko("Found %i entries\r\n",files);
			if(files<1) { deviceHandler_deinit(deviceHandler_initial); needsDeviceChange=1; break;}
			needsRefresh = 0;
			curMenuLocation=ON_FILLIST;
		}
		while(PAD_ButtonsHeld(0) & PAD_BUTTON_A) { VIDEO_WaitVSync (); }
		drawFiles(&allFiles, files);

		u16 btns = PAD_ButtonsHeld(0);
		if(curMenuLocation==ON_OPTIONS) {
			if(btns & PAD_BUTTON_LEFT){	curMenuSelection = (--curMenuSelection < 0) ? (MENU_MAX-1) : curMenuSelection;}
			else if(btns & PAD_BUTTON_RIGHT){curMenuSelection = (curMenuSelection + 1) % MENU_MAX;	}
		}
		if(deviceHandler_initial && ((btns & PAD_BUTTON_B)||(curMenuLocation==ON_FILLIST)))	{
			while(PAD_ButtonsHeld(0) & PAD_BUTTON_B){ VIDEO_WaitVSync (); }
			curMenuLocation=ON_FILLIST;
			renderFileBrowser(&allFiles, files);
		}
		else if(btns & PAD_BUTTON_A) {
			//handle menu event
			switch(curMenuSelection) {
				case 0:		// Device change
					needsDeviceChange = 1;  //Change from SD->DVD or vice versa
					break;
				case 1:		// Settings
					show_settings(NULL, NULL);
					break;
				case 2:		// Credits
					show_info();
					break;
				case 3:
					if(deviceHandler_initial) {
						memcpy(&curFile, deviceHandler_initial, sizeof(file_handle));
						if(curDevice == WKF) { 
							wkfReinit(); deviceHandler_deinit(deviceHandler_initial);
						}
					}
					needsRefresh=1;
					break;
				case 4:
					__libogc_exit(0);
					break;
			}
			
		}
		while (!(!(PAD_ButtonsHeld(0) & PAD_BUTTON_B) && !(PAD_ButtonsHeld(0) & PAD_BUTTON_A) && !(PAD_ButtonsHeld(0) & PAD_BUTTON_RIGHT) && !(PAD_ButtonsHeld(0) & PAD_BUTTON_LEFT))) {
			VIDEO_WaitVSync();
		}
		if(needsDeviceChange) {
			break;
		}
	}
}
Beispiel #25
0
int main(int argc, char** argv) {

  printf("Running MD Skeleton\n");
  /* Thread numbers for Host */

  int num_threads = 1;
  int teams = 1;

  /* Default value for number of force calculations */

  int iter = 100;

  /* Default value for system size (4*nx*ny*nz atoms)
   * nx, ny and nz are set to system_size if not specififed on commandline */

  int system_size = 20;
  int nx = -1;
  int ny = -1;
  int nz = -1;

  int neighbor_size = 1; // Default bin size for neighbor list construction

  double rho = 0.8442; // Number density of the system
  double delta = 0; // Scaling factor for random offsets of atom positions

  int device = 0; // Default device for GPU runs

  /* read in command-line arguments */

  for(int i = 0; i < argc; i++) {
    if((strcmp(argv[i], "-t") == 0) || (strcmp(argv[i], "--num_threads") == 0)) {
      num_threads = atoi(argv[++i]);
      continue;
    }

    if((strcmp(argv[i], "--teams") == 0)) {
      teams = atoi(argv[++i]);
      continue;
    }

    if((strcmp(argv[i], "-d") == 0) || (strcmp(argv[i], "--device") == 0))  {
      device = atoi(argv[++i]);
      continue;
    }

    if((strcmp(argv[i], "--delta") == 0)) {
      delta = atof(argv[++i]);
      continue;
    }

    if((strcmp(argv[i], "-i") == 0) || (strcmp(argv[i], "--iter") == 0))  {
      iter = atoi(argv[++i]);
      continue;
    }

    if((strcmp(argv[i], "-rho") == 0)) {
      rho = atoi(argv[++i]);
      continue;
    }

    if((strcmp(argv[i], "-s") == 0) || (strcmp(argv[i], "--size") == 0)) {
      system_size = atoi(argv[++i]);
      continue;
    }

    if((strcmp(argv[i], "-nx") == 0)) {
      nx = atoi(argv[++i]);
      continue;
    }

    if((strcmp(argv[i], "-ny") == 0)) {
      ny = atoi(argv[++i]);
      continue;
    }

    if((strcmp(argv[i], "-nz") == 0)) {
      nz = atoi(argv[++i]);
      continue;
    }

    if((strcmp(argv[i], "-b") == 0) || (strcmp(argv[i], "--neigh_bins") == 0))  {
      neighbor_size = atoi(argv[++i]);
      continue;
    }
  }

  if( nx < 0 ) nx = system_size;
  if( ny < 0 ) ny = system_size;
  if( nz < 0 ) nz = system_size;

  printf("-> Init Device\n");

#if defined( KOKKOS_HAVE_CUDA )
  Kokkos::Cuda::host_mirror_device_type::initialize(teams*num_threads);
  Kokkos::Cuda::SelectDevice select_device(device);
  Kokkos::Cuda::initialize(select_device);
#elif defined( KOKKOS_HAVE_OPENMP )
  Kokkos::OpenMP::initialize(teams*num_threads);
#elif defined( KOKKOS_HAVE_PTHREAD )
  Kokkos::Threads::initialize(teams*num_threads);
#endif

  System system;
  system.neigh_cut = 2.8;
  system.force_cut = 2.5;
  system.force_cutsq = system.force_cut*system.force_cut;
  system.delta = delta;

  printf("-> Build system\n");
  create_system(system,nx,ny,nz,rho);

  printf("-> Created %i atoms and %i ghost atoms\n",system.nlocal,system.nghost);

  system.nbinx = system.box.xprd/neighbor_size+1;
  system.nbiny = system.box.yprd/neighbor_size+1;
  system.nbinz = system.box.zprd/neighbor_size+1;


  printf("-> Building Neighborlist\n");

  neigh_setup(system);
  neigh_build(system);

  double2 ev = force(system,1);

  printf("-> Calculate Energy: %lf Virial: %lf\n",ev.x,ev.y);

  printf("-> Running %i force calculations\n",iter);

  Kokkos::Impl::Timer timer;

  for(int i=0;i<iter;i++) {
    force(system,0);
  }


  double time = timer.seconds();
  printf("Time: %e s for %i iterations with %i atoms\n",time,iter,system.nlocal);

  device_type::finalize();
}
size_t select_default_device(struct fmt_main *fmt) {
	return select_device(0, fmt);
}
Beispiel #27
0
int main(int argc, char *argv[])
{
    int ret = 0;


    if (argc < 2)
    {
        fprintf(stderr, "Usage: transalign_killer [--cldev=x.y] <input file>\n");
        fprintf(stderr, "  --cldev=x.y: x specifies the platform index, y the device index.\n");
        return 1;
    }


    long seq_length;
    char *sequence = load_text(argv[argc - 1], &seq_length);
    if (!sequence)
        return 1;

    seq_length--; // Cut final 0 byte

    // FIXME: All the following code relies on seq_length being a multiple of BASE.

    long round_seq_length = round_up_to_power_of_two(seq_length, BASE_EXP);

    long res_length = 0;
    for (long len = round_seq_length / BASE; len; len /= BASE)
        res_length += len;


    // Use some random index to be searched for here
    unsigned letter_index = seq_length / 2;


    // Select an OpenCL device
    cl_device_id dev = select_device(argc - 1, argv);
    if (!dev)
        return 1;

    // Initialize the OpenCL st...ack
    cl_context ctx = clCreateContext(NULL, 1, &dev, NULL, NULL, NULL);
    cl_command_queue queue = clCreateCommandQueue(ctx, dev, 0, NULL);

    // Load the OpenCL kernesl
    char *prog_src = load_text("trans.cl", NULL);
    if (!prog_src)
        return 1;
    cl_program prog = clCreateProgramWithSource(ctx, 1, (const char **)&prog_src, NULL, NULL);
    free(prog_src);

    // Build them
    clBuildProgram(prog, 0, NULL, NULL, NULL, NULL);
    cl_kernel k_iadd = clCreateKernel(prog, "k_iadd", NULL); // initial addition
    cl_kernel k_cadd = clCreateKernel(prog, "k_cadd", NULL); // consecutive addition
    assert(k_iadd);
    assert(k_cadd);


    // Create the result buffer
    unsigned *result = malloc(res_length * sizeof(unsigned));
    cl_mem result_gpu = clCreateBuffer(ctx, CL_MEM_READ_WRITE | HOST_PTR_POLICY, res_length * sizeof(unsigned), result, NULL);


    clock_start();

    /*** START OF ROCKET SCIENCE LEVEL RUNTIME-TIME INTENSIVE STUFF ***/

    // Bandwidth intensive stuff goes here

    // Copy the sequence to the video memory (or, generally speaking, the OpenCL device)
    cl_mem seq_gpu = clCreateBuffer(ctx, CL_MEM_READ_WRITE | HOST_PTR_POLICY, seq_length * sizeof(char), sequence, NULL);

    long bw1_time = clock_delta();


    // GPU intensive stuff goes here

    /**
     * First, transform every - and \0 into a 0 and every other character into a
     * 1. Then, add consecutive fields (BASE fields) together and store them at
     * the beginning of the result buffer.
     */
    clSetKernelArg(k_iadd, 0, sizeof(result_gpu), &result_gpu);
    clSetKernelArg(k_iadd, 1, sizeof(seq_gpu), &seq_gpu);
    clSetKernelArg(k_iadd, 2, sizeof(unsigned), &(unsigned){seq_length});
Beispiel #28
0
static int notify(processor_t::idp_notify msgid, ...)
{
  va_list va;
  va_start(va, msgid);

// A well behaving processor module should call invoke_callbacks()
// in his notify() function. If this function returns 0, then
// the processor module should process the notification itself
// Otherwise the code should be returned to the caller:

  int code = invoke_callbacks(HT_IDP, msgid, va);
  if ( code ) return code;

  switch ( msgid )
  {
    case processor_t::init:
      helper.create("$ tms320c3x");
      inf.mf = 1; // MSB first
      inf.wide_high_byte_first = 1;
      init_analyzer();
      break;

    case processor_t::term:
      free_ioports(ports, numports);
    default:
      break;

    case processor_t::newfile:   // new file loaded
      inf.wide_high_byte_first = 0;
      {
        segment_t *s0 = get_first_seg();
        if ( s0 != NULL )
        {
          set_segm_name(s0, "CODE");
          segment_t *s1 = get_next_seg(s0->startEA);
          for (int i = dp; i <= rVds; i++)
          {
            SetDefaultRegisterValue(s0, i, BADSEL);
            SetDefaultRegisterValue(s1, i, BADSEL);
          }
        }
      }
      select_device(IORESP_ALL);
      break;

    case processor_t::oldfile:   // old file loaded
      inf.wide_high_byte_first = 0;
      idpflags = (ushort)helper.altval(-1);
      {
        char buf[MAXSTR];
        if ( helper.supval(-1, buf, sizeof(buf)) > 0 )
          set_device_name(buf, IORESP_NONE);
      }
      break;

    case processor_t::closebase:
    case processor_t::savebase:
      helper.altset(-1, idpflags);
      break;

    case processor_t::is_basic_block_end:
      return is_basic_block_end() ? 2 : 0;
  }
  va_end(va);
  return 1;
}