int
main(int argc, char **argv)
{
    int n;

    /* Enable standard application logging */
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

    /* Load the SDL library */
    if (SDL_Init(SDL_INIT_AUDIO) < 0) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
        return (1);
    }

    /* Print available audio drivers */
    n = SDL_GetNumAudioDrivers();
    if (n == 0) {
        SDL_Log("No built-in audio drivers\n\n");
    } else {
        int i;
        SDL_Log("Built-in audio drivers:\n");
        for (i = 0; i < n; ++i) {
            SDL_Log("  %s\n", SDL_GetAudioDriver(i));
        }
        SDL_Log("\n");
    }

    SDL_Log("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());

    print_devices(0);
    print_devices(1);

    SDL_Quit();
    return 0;
}
Esempio n. 2
0
int
main(int argc, char **argv)
{
    /* Load the SDL library */
    if (SDL_Init(SDL_INIT_AUDIO) < 0) {
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
        return (1);
    }

    /* Print available audio drivers */
    int n = SDL_GetNumAudioDrivers();
    if (n == 0) {
        printf("No built-in audio drivers\n\n");
    } else {
        int i;
        printf("Built-in audio drivers:\n");
        for (i = 0; i < n; ++i) {
            printf("  %s\n", SDL_GetAudioDriver(i));
        }
        printf("\n");
    }

    printf("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());

    print_devices(0);
    print_devices(1);

    SDL_Quit();
    return 0;
}
Esempio n. 3
0
void cmd_list_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
    const char *error_str;

    if ( argc != 1 ) {
        if ( argc < 1 ) error_str = "Type must be specified!";
        else error_str = "Only one argument allowed!";

        goto on_error;
    }

    DeviceType type;

    if ( strcasecmp(argv[1], "in") == 0 ) /* Input devices */
        type = input;

    else if ( strcasecmp(argv[1], "out") == 0 ) /* Output devices */
        type = output;

    else {
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid type: %s", argv[1]);
        return;
    }

    print_devices(self, type);

    return;
on_error:
    print_err (self, error_str);
}
Esempio n. 4
0
main()
{
  	int     error = NO_PANIC_DUMP_HEADER;
	int	i, found = 0, retval = NO_PANIC_DUMP_HEADER;
	int	ret;

	/* build devices */
	ret = build_devices();
	assert(ret == 0);

	print_devices();

	p2_write();
}
Esempio n. 5
0
//*******************************************************************************************
//
// Function : standby_display
// Description : display board status such as AVR ip, server ip, countdown time, temparature
//
//*******************************************************************************************
void standby_display ( void )
{
	BYTE generic_buf[64];

	// update lcd display flag not set, exit from function
	if ( flag1.bits.update_display == 0 )
		return;
	flag1.bits.update_display = 0;
	// lcd display is displaying other information, wait until busy flag clear
	if ( flag1.bits.lcd_busy )
		return;
	// now displaying menu information, wait until exit from menu
	if ( menu_index )
		return;

	// display status on lcd line 1
	lcd_putc ( '\f' );
	lcd_print ( (BYTE*)standby_list[ standby_cursor - 1 ] );

	// display status devices on lcd line 2
	lcd_putc ( '\n' );
	if ( standby_cursor == 1 )
	{
		print_devices (generic_buf,ind_device_cur);
		
	}
	// display avr ip
	if ( standby_cursor == 2 )
	{
		print_ip ( generic_buf, (BYTE*)&avr_ip, 0 );
	}
	// display server ip
	else if ( standby_cursor == 3 )
	{
		print_ip ( generic_buf, (BYTE*)&server_ip, 0 );
	}
	// display countdown timer
	else if ( standby_cursor == 4 )
	{
		print_time ( generic_buf, count_time, 0 );
	}
	// display current temparature
	else if ( standby_cursor == 5 )
	{
		print_temp ( generic_buf );
	}
	lcd_print ( generic_buf );
}
Esempio n. 6
0
/*
 * The main !
 */
int
main(int	argc,
     char **	argv)
{
  int skfd = -1;		/* generic raw socket desc.	*/
  int goterr = 0;

  /* Create a channel to the NET kernel. */
  if((skfd = sockets_open()) < 0)
    {
      perror("socket");
      exit(-1);
    }

  /* No argument : show the list of all device + info */
  if(argc == 1)
    {
      print_devices(skfd);
      close(skfd);
      exit(0);
    }

  /* Special case for help... */
  if((!strncmp(argv[1], "-h", 9)) ||
     (!strcmp(argv[1], "--help")))
    {
      iw_usage();
      close(skfd);
      exit(0);
    }

  /* The device name must be the first argument */
  if(argc == 2)
    {
      print_info(skfd, argv[1]);
      close(skfd);
      exit(0);
    }

  /* The other args on the line specify options to be set... */
  goterr = set_info(skfd, argv + 2, argc - 2, argv[1]);

  /* Close the socket. */
  close(skfd);

  return(goterr);
}
static void test_find_devices(int handle)
{
	int devarr[DEVARRSIZ];
	int ndev = -1;
	int i = 0;

	for(i=0; i <3; i++)
	{
		printf("\n**\n Plug/Unplug USB cables, \n Press enter \n**\n");

		getchar();

		ndev = PasGetDevices(handle, devarr, DEVARRSIZ);
		print_devices(devarr,ndev);

	}

}
Esempio n. 8
0
/* delete device_list[d], and close the file descriptor that is open on
 * that device.
 */
void delete_device(int d)
{
    int i;
    int result;
    
    if (db[0].d) { ddprintf("hi from delete_device..\n"); }

    result = close(device_list[d].fd);
    if (result != 0) {
        ddprintf("delete_device:  could not close %s\n",
                device_list[d].device_name);
    }

    for (i = d; i < device_list_count - 1; i++) {
        device_list[i] = device_list[i + 1];
    }
    device_list_count--;

    if (db[0].d) { print_devices(); }
}
Esempio n. 9
0
int main(int argc, char *argv[])
{
	libusb_device **devs;
	libusb_context *context = NULL;
	
	size_t list;
	size_t i;
	int ret;

	ret = libusb_init(&context);

	if(ret < 0)
	{
		perror("libusb_init");
		exit(1);
	}

	list = libusb_get_device_list(context, &devs);

	if(list < 0)
	{
		fprinf(stderr, "Error in getting device list\n");
		libusb_free_device_list(devs,1);
		libusb_exit(context);
		exit(1);
	}

	printf("There are %d devices found", list);

	for(i = 0; i < list; i++)
	{
		print_devices(devs[i]);
	}
	
	libusb_free_device_list(devs, 1);
	libusb_exit(context);

	return 0;
}
Esempio n. 10
0
/* for interface "device_name" (i.e., eth0 etc.), open a raw socket to
 * the interface and get a file descriptor for the socket.  add the
 * interface (file descriptor and all) to device_list[].
 *
 * as a special case, if the device type is an ad-hoc, that means this
 * is a description of another cloud box that we are communicating with
 * in ad-hoc mode.  in that case, find and copy the device_list[] entry
 * for our wireless lan interface.
 */
void add_device(char *device_name, mac_address_t mac_address,
        device_type_t device_type)
{
    device_t *device;
    static struct ifreq get_index;
    int result;
    struct sockaddr_ll bind_arg;
    mac_address_t mac_addr;
    int i;
    device_t *wlan;

    if (device_list_count >= MAX_CLOUD) {
        ddprintf("add_device:  too many devices.\n");
        goto finish;
    }

    device = &device_list[device_list_count];

    device->sim_device = 0;
    device->expect_k = 0;
    device->expect_n = -1;

    // if (db[0].d) {
        ddprintf("hi from add_device(%s)..\n", device_name);
    // }

    if (strstr(device_name, "wds") != NULL && device_type == device_type_wds) {
        device->device_type = device_type_wds;

    } else if (strstr(device_name, "wds") != NULL
        && device_type == device_type_cloud_wds)
    {
        device->device_type = device_type_cloud_wds;

    } else if (strcmp(device_name, wlan_device_name) == 0
        && device_type == device_type_wlan)
    {
        device->device_type = device_type_wlan;

    } else if (eth_device_name != NULL
        && strcmp(device_name, eth_device_name) == 0)
    {
        device->device_type = device_type_eth;

    } else if (have_mon_device &&
        strcmp(device_name, wlan_mon_device_name) == 0)
    {
        device->device_type = device_type_wlan_mon;

    } else if (ad_hoc_mode && device_type == device_type_ad_hoc) {
        bool_t found = false;
        device->device_type = device_type_ad_hoc;
        for (i = 0; i < device_list_count; i++) {
            if (device_list[i].device_type == device_type_wlan) {
                found = true;
                wlan = &device_list[i];
                break;
            }
        }
        if (!found) {
            ddprintf("add_device; couldn't find wireless device in ad_hoc mode");
            goto finish;
        }

    } else if (/*ad_hoc_mode &&*/ device_type == device_type_cloud_wlan) {
        device->device_type = device_type_cloud_wlan;

    } else if (/*ad_hoc_mode &&*/ device_type == device_type_cloud_eth) {
        device->device_type = device_type_cloud_eth;

    } else {
        ddprintf("add_device; unknown device_type '%s'\n", device_name);
        goto finish;
    }

    if (mac_address == 0) {
        result = mac_get(mac_addr, device_name);
        if (result != 0) {
            ddprintf("add_device:  mac_get on %s failed.\n",
                    device_name);
            goto finish;
        }
    } else {
        mac_copy(mac_addr, mac_address);
    }

    if (ad_hoc_mode && device_type == device_type_ad_hoc) {
        sprintf(device->device_name, wlan_device_name);
    } else {
        sprintf(device->device_name, device_name);
    }

    mac_copy(device->mac_address, mac_addr);

    if (use_pipes) {
        char fname[PATH_MAX];
        int fd;
        sprintf(fname, "%s/%s.cloud", pipe_directory, device_name);
        fd = repeat_open(fname, O_RDWR);
        ddprintf("opening wlan input device %s; fd %d\n", fname, fd);
        if (fd == -1) {
            ddprintf("add_device; could not open pipe %s:  %s\n", 
                    fname, strerror(errno));
            goto finish;
        }
        device->fd = fd;
        pio_init_from_fd(&device->in_pio, fname, fd);
        ddprintf("done..\n");

        sprintf(fname, "%s/%s.cooked", pipe_directory, device_name);
        fd = repeat_open(fname, O_RDWR);
        ddprintf("opening wlan output device %s; fd %d\n", fname, fd);
        if (fd == -1) {
            ddprintf("add_device; could not open pipe %s:  %s\n", 
                    fname, strerror(errno));
            goto finish;
        }
        device->out_fd = fd;
        pio_init_from_fd(&device->out_pio, fname, fd);
        ddprintf("done..\n");

    } else if (ad_hoc_mode && device_type == device_type_ad_hoc) {
        device->fd = wlan->fd;
        device->if_index = wlan->if_index;

    } else {
        device->fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
        if (device->fd == -1) {
            ddprintf("add_device:  socket failed\n");
            goto finish;
        }

        /* after a change of wep key, this fails. may need to delete and
         * re-create wds interface?
         */
        sprintf(get_index.ifr_name, device_name);
        result = ioctl(device->fd, SIOCGIFINDEX, &get_index);
        if (result == -1) {
            ddprintf("add_device:  could not get device index\n");
            goto finish;
        }
        device->if_index = get_index.ifr_ifindex;

        memset(&bind_arg, 0, sizeof(bind_arg));
        bind_arg.sll_family = AF_PACKET;
        bind_arg.sll_ifindex = get_index.ifr_ifindex;

        if (device_type == device_type_cloud_wlan
            || device_type == device_type_cloud_eth
            || device_type == device_type_cloud_wds)
        {
            bind_arg.sll_protocol = htons(CLOUD_MSG);

        } else if (db[47].d
            && ((ad_hoc_mode && !db[50].d && device_type == device_type_wlan)
                || device_type == device_type_wds))
        {
            bind_arg.sll_protocol = htons(WRAPPED_CLIENT_MSG);

        } else {
            bind_arg.sll_protocol = htons(ETH_P_ALL);
        }

        result = bind(device->fd, (struct sockaddr *) &bind_arg,
                sizeof(bind_arg));
        if (result == -1) {
            ddprintf("add_device:  bind failed\n");
            goto finish;
        }
    }

    if (db[50].d && device_type == device_type_ad_hoc) {
        ad_hoc_client_add(device->mac_address);
    }

    add_io_stat(device);

    device_list_count++;

    finish :

    // if (db[0].d) {
        ddprintf("this device:\n");
        print_device(eprintf, stderr, &device_list[device_list_count - 1]);
        ddprintf("all devices:\n");
        print_devices();
    // }

} /* add_device */
Esempio n. 11
0
int main(int argc, char **argv)
{
        int c;
        char *domain = NULL;
        char *uri = "xen";
        char *file = NULL;
        bool xml = false;
        bool cap = false;
        struct domain *dominfo = NULL;
        struct capabilities *capsinfo = NULL;
        struct cap_domain_info *capgdinfo = NULL;
        int ret;

        static struct option lopts[] = {
                {"domain", 1, 0, 'd'},
                {"uri",    1, 0, 'u'},
                {"xml",    0, 0, 'x'},
                {"file",   1, 0, 'f'},
                {"cap",    0, 0, 'c'},
                {"help",   0, 0, 'h'},
                {0,        0, 0, 0}};

        while (1) {
                int optidx = 0;

                c = getopt_long(argc, argv, "d:u:f:xch", lopts, &optidx);
                if (c == -1)
                        break;

                switch (c) {
                case 'd':
                        domain = optarg;
                        break;

                case 'u':
                        uri = optarg;
                        break;

                case 'f':
                        file = optarg;
                        break;

                case 'x':
                        xml = true;
                        break;

                case 'c':
                        cap = true;
                        break;

                case '?':
                case 'h':
                        usage();
                        return c == '?';
                };
        }

        if (file != NULL)
                ret = dominfo_from_file(file, &dominfo);
        else if (domain != NULL)
                ret = dominfo_from_dom(uri, domain, &dominfo);
        else {
                printf("Need a data source (--domain or --file)\n");
                return 1;
        }

        if (ret == 0) {
                printf("Unable to get dominfo\n");
                return 2;
        }

        if (xml)
                print_domxml(dominfo, stdout);
        else {
                print_dominfo(dominfo, stdout);
                print_devices(dominfo, stdout);
        }

        if (cap && file == NULL) {
                ret = capinfo_for_dom(uri, dominfo, &capsinfo);
                if (ret == 0) {
                        printf("Unable to get capsinfo\n");
                        return 3;
                } else {
                        print_capabilities(capsinfo, stdout);
                        const char *os_type = get_ostype(dominfo);
                        const char *dom_type = get_domaintype(dominfo);
                        const char *def_arch = get_default_arch(capsinfo, os_type);

                        fprintf(stdout, "-- KVM is used: %s\n\n", (use_kvm(capsinfo)?"true":"false"));
                        fprintf(stdout, "-- For all following default OS type=%s\n", os_type);
                        fprintf(stdout, "-- Default Arch : %s\n", def_arch);

                        fprintf(stdout,
                                "-- Default Machine for arch=NULL : %s\n",
                                get_default_machine(capsinfo, os_type, NULL, NULL));
                        fprintf(stdout,
                                "-- Default Machine for arch=%s and domain type=NULL : %s\n",
                                def_arch,
                                get_default_machine(capsinfo, os_type, def_arch, NULL));
                        fprintf(stdout,
                                "-- Default Machine for arch=%s and domain type=%s : %s\n",
                                def_arch, dom_type,
                                get_default_machine(capsinfo, os_type, def_arch, dom_type));
                        fprintf(stdout,
                                "-- Default Machine for arch=NULL and domain type=%s : %s\n",
                                dom_type,
                                get_default_machine(capsinfo, os_type, NULL, dom_type));

                        fprintf(stdout,
                                "-- Default Emulator for arch=NULL : %s\n",
                                get_default_emulator(capsinfo, os_type, NULL, NULL));
                        fprintf(stdout,
                                "-- Default Emulator for arch=%s and domain type=NULL : %s\n",
                                def_arch,
                                get_default_emulator(capsinfo, os_type, def_arch, NULL));
                        fprintf(stdout,
                                "-- Default Emulator for arch=%s and domain type=%s : %s\n",
                                def_arch, dom_type,
                                get_default_emulator(capsinfo, os_type, def_arch, dom_type));
                        fprintf(stdout,
                                "-- Default Emulator for arch=NULL and domain type=%s : %s\n",
                                dom_type,
                                get_default_emulator(capsinfo, os_type, NULL, dom_type));

                        fprintf(stdout, "\n-- Default Domain Search for: \n"
                                "guest type=hvm - guest arch=* - guest domain type=kvm\n");
                        capgdinfo = findDomainInfo(capsinfo, "hvm", NULL, "kvm");
                        print_cap_domain_info(capgdinfo, stdout);

                        fprintf(stdout, "-- Default Domain Search for: \n"
                                "guest type=* - guest arch=* - guest domain type=*\n");
                        capgdinfo = findDomainInfo(capsinfo, NULL, NULL, NULL);
                        print_cap_domain_info(capgdinfo, stdout);

                        cleanup_capabilities(&capsinfo);
                }
        } else if (cap) {
                printf("Need a data source (--domain) to get default capabilities\n");
                return 4;
        }

        cleanup_dominfo(&dominfo);

        return 0;
}
Esempio n. 12
0
int main(int argc, char *argv[])
{		
	// Variables	
	// Default CSS
	char CSSFILE[12]="style.css";

	// Pointers to filenames
	char *infofilename = INFO;
	char *logfilename = LOG;
	
	// Handle arguments
	int opt;
	while ((opt=getopt_long(argc, argv, "dvhm", main_options, NULL)) != EOF)
	{
		switch (opt)
		{
		case 'h':
			help();
			exit(0);
		case 'd':
			debug();
			exit(0);
		case 'v':
			printf("%s (v%s) by MS3FGX\n", APPNAME, VERSION);
			exit(0);
			break;
		case 'm':
			strcpy(CSSFILE, "mobile.css");
			mobile = 1;
			break;
		default:
			printf("Unknown option.\n");
			exit(0);
		}
	}
	
	// Bail out if we are root, except on WRT
	#ifndef OPENWRT
	if(getuid() == 0)
	{
		syslog(LOG_ERR,"CGI module refusing to run as root!");
		printf("Server attempting to run CGI module as root, bailing out!\n");
		printf("Check your web server configuration and try again.\n");
		exit(1);
	}
	#endif

	// Read in environment variable
	// Comment this to fix compiler warning until ready to implement
	//char* env_string;
	//env_string=getenv("QUERY_STRING");

	// Print HTML head
	print_header(CSSFILE);
	//print_html(CSSFILE);
	
	// Start container div
	if (!mobile)
		puts("<div id=\"container\">\n");

	// Open files
	if ((infofile = fopen(infofilename, "r")) == NULL)
	{
		syslog(LOG_ERR,"Error while opening %s!",infofilename);
		puts("<div id=\"content\">");
		printf("Error while opening %s!\n",infofilename);
		puts("</body></html>");
		exit(1);
	}
	
	if ((logfile = fopen(logfilename, "r")) == NULL)
	{
		syslog(LOG_ERR,"Error while opening %s!",logfilename);
		puts("<div id=\"content\">");
		printf("Error while opening %s!\n",logfilename);
		puts("</body></html>");
		exit(1);
	}
	
	// Draw sidebar\topbar
	read_log();
	if (!mobile)
		SideBar();
	else
		TopBar();
	
	// Content window
	puts("<div id=\"content\">");
	
	if (device_index > 0)
	{
		// Print results
		setup_table();
		print_devices();
		puts("</table>\n");
	}
	
	// Close content, body, and HTML
	puts("</div></body></html>");
	
	// Close files and exit
	shut_down();
	return 0;
}
Esempio n. 13
0
/*
 * interactively select a kernel image and options.
 * The kernel can be an actual filename or a label in the config file
 * Return:
 * 	-1: if unsucessful
 * 	 0: otherwise
 */
static INTN
select_kernel(CHAR16 *buffer, INTN size)
{
#define CHAR_CTRL_C	L'\003' /* Unicode CTRL-C */
#define CHAR_CTRL_D	L'\004' /* Unicode CTRL-D */
#define CHAR_CTRL_U	L'\025' /* Unicode CTRL-U */
//#define CHAR_TAB	L'\t'
	SIMPLE_INPUT_INTERFACE *ip = systab->ConIn;
	EFI_INPUT_KEY key;
	EFI_STATUS status;
	INTN pos = 0, ret;
	INT8 first_time = 1;

	/* 
	 * let's give some help first
	 */
	print_help(0);

	print_infos(0);

reprint:
	buffer[pos] = CHAR_NULL;

	Print(L"\nELILO boot: %s", buffer);
	/*
	 * autoboot with default choice after timeout expires
	 */
	if (first_time && (ret=wait_timeout(elilo_opt.timeout)) != 1) {
		return ret == -1 ? -1: 0;
	}
	first_time = 0;

	for (;;) {
		while ((status = uefi_call_wrapper(ip->ReadKeyStroke, 2, ip, &key))
				 == EFI_NOT_READY);
		if (EFI_ERROR(status)) {
			ERR_PRT((L"select_kernel readkey: %r", status));
			return -1;
		} 
		switch (key.UnicodeChar) {
			case CHAR_TAB:
				Print(L"\n");
				if (pos == 0) {
					print_label_list();
					Print(L"(or a kernel file name: [[dev_name:/]path/]kernel_image cmdline options)\n");
				} else {
					buffer[pos] = CHAR_NULL;
					display_label_info(buffer);
				}
				goto reprint;
			case L'%':
				if (pos>0) goto normal_char;
				Print(L"\n");
				print_vars();
				goto reprint;
			case L'?':
				if (pos>0) goto normal_char;
				Print(L"\n");
				print_help(1);
				goto reprint;
			case L'&':
				if (pos>0) goto normal_char;
				Print(L"\n");
				print_infos(1);
				goto reprint;
			case L'=':
				if (pos>0) goto normal_char;
				Print(L"\n");
				print_devices();
				goto reprint;
			case CHAR_BACKSPACE:
				if (pos == 0) break;
				pos--;
				Print(L"\b \b");
				break;
			case CHAR_CTRL_U: /* clear line */
				while (pos) {
					Print(L"\b \b");
					pos--;
				}
				break;
			case CHAR_CTRL_C: /* kill line */
				pos = 0;
				goto reprint;
			case CHAR_LINEFEED:
			case CHAR_CARRIAGE_RETURN:
				buffer[pos]   = CHAR_NULL;
				Print(L"\n");
				return 0;
			default:
normal_char:
				if (key.UnicodeChar == CHAR_CTRL_D || key.ScanCode == 0x17 ) {
					Print(L"\nGiving up then...\n");
					return  -1;
				}
				if (key.UnicodeChar == CHAR_NULL) break;

				if (pos > size-1) break;

				buffer[pos++] = key.UnicodeChar;

				/* Write the character out */
				Print(L"%c", key.UnicodeChar);
		}
	}
	return 0;
}
Esempio n. 14
0
void
setup_opencl(const char* cl_source_filename, const char* cl_source_main, cl_device_id* device_id,
             cl_kernel* kernel, cl_context* context, cl_command_queue* queue)
{
        cl_int err;					// error code returned from api calls

        cl_platform_id platform_id;			// compute device id
        cl_program program;				// compute program
        cl_device_id devices[MAX_RESOURCES];
        cl_platform_id platforms[MAX_RESOURCES];


        unsigned int best_platform = 0;
        unsigned int best_device = 0;
        print_devices(0);

        if(!get_best_device(&best_platform, &best_device)) {
                printf("No suitable device was found! Try using an OpenCL1.1 compatible device.\n");
                exit(1);
        }
        printf("Initiating platform-%d device-%d.\n", best_platform, best_device);



        // Platform
        err = clGetPlatformIDs(MAX_RESOURCES, platforms, NULL);
	ocl_error("Getting platform id", err);

        platform_id = platforms[best_platform];

        // Device
        err = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_ALL, sizeof(devices), devices, NULL); //NULL, ignore number returned devices.
	ocl_error("Getting device ids", err);

        *device_id = devices[best_device];

        // Context
        *context = clCreateContext(0, 1, device_id, NULL, NULL, &err);
	ocl_error("Creating context", err);

        // Command-queue
        *queue = clCreateCommandQueue(*context, *device_id, 0, &err);
	ocl_error("Creating command queue", err);


        // Read .cl source into memory
        int cl_source_len = 0;
        char* cl_source = file_contents(cl_source_filename, &cl_source_len);


        // Create thes compute program from the source buffer
        program = clCreateProgramWithSource(*context, 1, (const char **) &cl_source, NULL, &err);
	ocl_error("Failed to create compute program", err);


        // Build the program executable
        err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
        if (err != CL_SUCCESS) {
                char* build_log;
                size_t log_size;
                // First call to know the proper size
                clGetProgramBuildInfo(program, *device_id, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);
                build_log = malloc(sizeof(char)*(log_size+1));
                if(log_size > 0 && build_log != NULL) {
	                // Second call to get the log
	                clGetProgramBuildInfo(program, *device_id, CL_PROGRAM_BUILD_LOG, log_size, build_log, NULL);
	                build_log[log_size] = '\0';
	                printf("%s\n", build_log);
	                free(build_log);
                }

                exit(err);
        }


        // Create the compute kernel in the program we wish to run
        *kernel = clCreateKernel(program, cl_source_main, &err);
	ocl_error("Failed to create compute kernel", err);
}
Esempio n. 15
0
int main(int argc, char *argv[]) {
    print_devices();
    print_hello();
    return 0;
}
Esempio n. 16
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
}
Esempio n. 17
0
//------------------------------------------------------------------------------
void print_platforms() {
    cl_uint numPlatforms = 0;
    cl_platform_id platform = 0;
    cl_int status = clGetPlatformIDs(0, 0, &numPlatforms);
    if(status != CL_SUCCESS) {
        std::cerr << "ERROR - clGetPlatformIDs()" << std::endl;
        exit(EXIT_FAILURE);
    }
    if(numPlatforms < 1) {
        std::cout << "No OpenCL platform detected" << std::endl;
        exit(EXIT_SUCCESS);
    }
    typedef std::vector< cl_platform_id > PlatformIds;
    PlatformIds platforms(numPlatforms);
    status = clGetPlatformIDs(platforms.size(), &platforms[0], 0);
    if(status != CL_SUCCESS) {
        std::cerr << "ERROR - clGetPlatformIDs()" << std::endl;
        exit(EXIT_FAILURE);
    }
    std::vector< char > buf(0x10000, char(0));
    int p = 0;
    std::cout << "\n***************************************************\n";
    std::cout << "Number of platforms: " << platforms.size() << std::endl;
    for(PlatformIds::const_iterator i = platforms.begin();
            i != platforms.end(); ++i, ++p) {

        std::cout << "\n-----------\n";
        std::cout << "Platform " << p << std::endl;
        std::cout << "-----------\n";
        status = ::clGetPlatformInfo(*i, CL_PLATFORM_VENDOR,
                                     buf.size(), &buf[ 0 ], 0 );
        if(status != CL_SUCCESS) {
            std::cerr << "ERROR - clGetPlatformInfo(): " << std::endl;
            exit(EXIT_FAILURE);
        }
        std::cout << "Vendor: " << &buf[ 0 ] << '\n';
        status = ::clGetPlatformInfo(*i, CL_PLATFORM_PROFILE,
                                     buf.size(), &buf[ 0 ], 0 );
        if(status != CL_SUCCESS) {
            std::cerr << "ERROR - clGetPlatformInfo(): " << std::endl;
            exit(EXIT_FAILURE);
        }
        std::cout << "Profile: " << &buf[ 0 ] << '\n';
        status = ::clGetPlatformInfo(*i, CL_PLATFORM_VERSION,
                                     buf.size(), &buf[ 0 ], 0 );
        if(status != CL_SUCCESS) {
            std::cerr << "ERROR - clGetPlatformInfo(): " << std::endl;
            exit(EXIT_FAILURE);
        }
        std::cout << "Version: " << &buf[ 0 ] << '\n';
        status = ::clGetPlatformInfo(*i, CL_PLATFORM_NAME,
                                     buf.size(), &buf[ 0 ], 0 );
        if(status != CL_SUCCESS) {
            std::cerr << "ERROR - clGetPlatformInfo(): " << std::endl;
            exit(EXIT_FAILURE);
        }
        std::cout << "Name: " << &buf[ 0 ] << '\n';
        status = ::clGetPlatformInfo(*i, CL_PLATFORM_EXTENSIONS,
                                     buf.size(), &buf[ 0 ], 0 );
        if(status != CL_SUCCESS) {
            std::cerr << "ERROR - clGetPlatformInfo(): " << std::endl;
            exit(EXIT_FAILURE);
        }
        std::cout << "Extensions: " << &buf[ 0 ] << '\n';
        print_devices(*i);
        std::cout << "\n===================================================\n";

    }
}
Esempio n. 18
0
int
main(int argc, char **argv)
{
    int opt;

    program_options_t options;
    options.backend = NULL;
    options.devname = NULL;
    options.xmlfile = "output.uddf";
    options.truncateDives = 0;
    options.initialPressureFix = 0;
    options.logfile = "output.log";
    options.dumpDives = 1;
    options.dumpMemory = 0;
    options.useInvalidElements = 0;

    static struct option long_options[] = {
            {"backend",      required_argument, NULL, 'b'},
            {"device",       required_argument, NULL, 'd'},
            {"output",       required_argument, NULL, 'o'},
            {"help",         no_argument,       NULL, 'h'},
            {"ipf",          no_argument,       NULL, 'i'},
            {"truncate",     no_argument,       NULL, 't'},
            {"invalid",      no_argument,       NULL, 0},
            {"listdevices",  no_argument,       NULL, 0},
            {"listbackends", no_argument,       NULL, 0},
            {NULL,           no_argument,       NULL, 0}
    };
    char *getopt_short = "b:d:o:hit";
    /* getopt_long stores the option index here. */
    int option_index = 0;

    opt = getopt_long (argc, argv, getopt_short,
            long_options, &option_index);
    while (opt != -1)
    {
        switch (opt)
        {
        case 0:
            /* If this option set a flag, do nothing else now. */
            if (long_options[option_index].flag != 0)
                break;
            if (g_strcmp0("listdevices", long_options[option_index].name) == 0) {
                print_devices();
            }
            if (g_strcmp0("listbackends", long_options[option_index].name) == 0) {
                print_backends();
            }
            if (g_strcmp0("invalid", long_options[option_index].name) == 0) {
                options.useInvalidElements = 1;
            }
            break;

        case 'b':
            options.backend = optarg;
            break;

        case 'd':
            options.devname = optarg;
            break;

        case 'o':
            options.xmlfile = optarg;
            break;

        case 'i':
            options.initialPressureFix = 1;
            break;

        case 't':
            options.truncateDives = 1;
            break;

        case '?':
        case 'h':
            usage();
            break;

        default:
            printf("Unknown argument: %c", (char)opt);
            return EXIT_FAILURE;
        }
        opt = getopt_long (argc, argv, getopt_short,
                long_options, &option_index);
    }

    if (options.backend == NULL || options.devname == NULL) {
        usage();
    }

    return dump_dives(&options);
}