int print_device_list(struct device *dev) { if (dev == NULL) return EXIT_FAILURE; printf("------%s------\n", dev->name); print_info_tuple_list(dev->info); print_device_list(dev->child); printf("------------\n"); print_device_list(dev->next); return EXIT_SUCCESS; }
int main(void) { struct device *dev = new_device("Plugin"); get_info(dev); print_device_list(dev); free_device(&dev); return 0; }
void MultiOpenCLDev::BuildContext() { if (is_valid) return; oclGetPlatformIDs(); oclGetDevices(); oclCreateContexts(); oclCreateCommandQueue(); print_device_list(); is_valid = true; }
static int open_output(void) { double rate; int n, nrates, include_enc, exclude_enc, ret; PaSampleFormat SampleFormat, nativeSampleFormats; if( dpm.name != NULL) ret = sscanf(dpm.name, "%d", &opt_pa_device_id); if (dpm.name == NULL || ret == 0 || ret == EOF) opt_pa_device_id = -2; #ifdef AU_PORTAUDIO_DLL #if PORTAUDIO_V19 { if(&dpm == &portaudio_asio_play_mode){ HostApiTypeId = paASIO; } else if(&dpm == &portaudio_win_ds_play_mode){ HostApiTypeId = paDirectSound; } else if(&dpm == &portaudio_win_wmme_play_mode){ HostApiTypeId = paMME; } else { return -1; } if(load_portaudio_dll(0)) return -1; } #else { if(&dpm == &portaudio_asio_play_mode){ if(load_portaudio_dll(PA_DLL_ASIO)) return -1; } else if(&dpm == &portaudio_win_ds_play_mode){ if(load_portaudio_dll(PA_DLL_WIN_DS)) return -1; } else if(&dpm == &portaudio_win_wmme_play_mode){ if(load_portaudio_dll(PA_DLL_WIN_WMME)) return -1; } else { return -1; } } #endif #endif /* if call twice Pa_OpenStream causes paDeviceUnavailable error */ if(pa_active == 1) return 0; if(pa_active == 0){ err = Pa_Initialize(); if( err != paNoError ) goto error; pa_active = 1; } if (opt_pa_device_id == -1){ print_device_list(); goto error2; } #ifdef PORTAUDIO_V19 #ifdef AU_PORTAUDIO_DLL { PaHostApiIndex i, ApiCount; i = 0; ApiCount = Pa_GetHostApiCount(); do{ HostApiInfo=Pa_GetHostApiInfo(i); if( HostApiInfo->type == HostApiTypeId ) break; i++; }while ( i < ApiCount ); if ( i == ApiCount ) goto error; DeviceIndex = HostApiInfo->defaultOutputDevice; if(DeviceIndex==paNoDevice) goto error; } #else DeviceIndex = Pa_GetDefaultOutputDevice(); if(DeviceIndex==paNoDevice) goto error; #endif DeviceInfo = Pa_GetDeviceInfo( DeviceIndex); if(DeviceInfo==NULL) goto error; if(opt_pa_device_id != -2){ const PaDeviceInfo *id_DeviceInfo; id_DeviceInfo=Pa_GetDeviceInfo((PaDeviceIndex)opt_pa_device_id); if(id_DeviceInfo==NULL) goto error; if( DeviceInfo->hostApi == id_DeviceInfo->hostApi){ DeviceIndex=(PaDeviceIndex)opt_pa_device_id; DeviceInfo = id_DeviceInfo; } } if (dpm.encoding & PE_24BIT) { SampleFormat = paInt24; }else if (dpm.encoding & PE_16BIT) { SampleFormat = paInt16; }else { SampleFormat = paInt8; } stereo = (dpm.encoding & PE_MONO) ? 1 : 2; data_nbyte = (dpm.encoding & PE_16BIT) ? 2 : 1; data_nbyte = (dpm.encoding & PE_24BIT) ? 3 : data_nbyte; pa_data.samplesToGo = 0; pa_data.bufpoint = pa_data.buf; pa_data.bufepoint = pa_data.buf; // firsttime = 1; numBuffers = 1; //Pa_GetMinNumBuffers( framesPerBuffer, dpm.rate ); framesPerInBuffer = numBuffers * framesPerBuffer; if (framesPerInBuffer < 4096) framesPerInBuffer = 4096; bytesPerInBuffer = framesPerInBuffer * data_nbyte * stereo; /* set StreamParameters */ StreamParameters.device = DeviceIndex; StreamParameters.channelCount = stereo; if(ctl->id_character != 'r' && ctl->id_character != 'A' && ctl->id_character != 'W' && ctl->id_character != 'P'){ StreamParameters.suggestedLatency = DeviceInfo->defaultHighOutputLatency; }else{ StreamParameters.suggestedLatency = DeviceInfo->defaultLowOutputLatency; } StreamParameters.hostApiSpecificStreamInfo = NULL; if( SampleFormat == paInt16){ StreamParameters.sampleFormat = paInt16; if( paFormatIsSupported != Pa_IsFormatSupported( NULL , &StreamParameters,(double) dpm.rate )){ StreamParameters.sampleFormat = paInt32; conv16_32 = 1; } else { StreamParameters.sampleFormat = paInt16; conv16_32 = 0; } }else{ StreamParameters.sampleFormat = SampleFormat; } err = Pa_IsFormatSupported( NULL , &StreamParameters, (double) dpm.rate ); if ( err != paNoError) goto error; err = Pa_OpenStream( & stream, /* passes back stream pointer */ NULL, /* inputStreamParameters */ &StreamParameters, /* outputStreamParameters */ (double) dpm.rate, /* sample rate */ paFramesPerBufferUnspecified, /* frames per buffer */ paFramesPerBufferUnspecified, /* PaStreamFlags */ paCallback, /* specify our custom callback */ &pa_data /* pass our data through to callback */ ); // Pa_Sleeep(1); if ( err != paNoError) goto error; return 0; #else if(opt_pa_device_id == -2){ DeviceID = Pa_GetDefaultOutputDeviceID(); if(DeviceID==paNoDevice) goto error2; }else{ DeviceID = opt_pa_device_id; } DeviceInfo = Pa_GetDeviceInfo( DeviceID); if(DeviceInfo==NULL) goto error2; nativeSampleFormats = DeviceInfo->nativeSampleFormats; exclude_enc = PE_ULAW | PE_ALAW | PE_BYTESWAP; include_enc = PE_SIGNED; if (!(nativeSampleFormats & paInt16) && !(nativeSampleFormats & paInt32)) {exclude_enc |= PE_16BIT;} if (!(nativeSampleFormats & paInt24)) {exclude_enc |= PE_24BIT;} dpm.encoding = validate_encoding(dpm.encoding, include_enc, exclude_enc); if (dpm.encoding & PE_24BIT) { SampleFormat = paInt24; }else if (dpm.encoding & PE_16BIT) { if(nativeSampleFormats & paInt16) SampleFormat = paInt16; else{ SampleFormat = paInt32; conv16_32 = 1; } }else { SampleFormat = paInt8; } stereo = (dpm.encoding & PE_MONO) ? 1 : 2; data_nbyte = (dpm.encoding & PE_16BIT) ? 2 : 1; data_nbyte = (dpm.encoding & PE_24BIT) ? 3 : data_nbyte; nrates = DeviceInfo->numSampleRates; if (nrates == -1) { /* range supported */ rate = dpm.rate; if (dpm.rate < DeviceInfo->sampleRates[0]) rate = DeviceInfo->sampleRates[0]; if (dpm.rate > DeviceInfo->sampleRates[1]) rate = DeviceInfo->sampleRates[1]; } else { rate = DeviceInfo->sampleRates[nrates-1]; for (n = nrates - 1; n >= 0; n--) { /* find nearest sample rate */ if (dpm.rate <= DeviceInfo->sampleRates[n]) rate=DeviceInfo->sampleRates[n]; } } dpm.rate = (int32)rate; pa_data.samplesToGo = 0; pa_data.bufpoint = pa_data.buf; pa_data.bufepoint = pa_data.buf; // firsttime = 1; numBuffers = Pa_GetMinNumBuffers( framesPerBuffer, dpm.rate ); framesPerInBuffer = numBuffers * framesPerBuffer; if (framesPerInBuffer < 4096) framesPerInBuffer = 4096; bytesPerInBuffer = framesPerInBuffer * data_nbyte * stereo; // printf("%d\n",framesPerInBuffer); // printf("%d\n",dpm.rate); err = Pa_OpenDefaultStream( &stream, /* passes back stream pointer */ 0, /* no input channels */ stereo, /* 2:stereo 1:mono output */ SampleFormat, /* 24bit 16bit 8bit output */ (double)dpm.rate, /* sample rate */ framesPerBuffer, /* frames per buffer */ numBuffers, /* number of buffers, if zero then use default minimum */ paCallback, /* specify our custom callback */ &pa_data); /* pass our data through to callback */ if ( err != paNoError && err != paHostError) goto error; return 0; #endif error: ctl->cmsg( CMSG_ERROR, VERB_NORMAL, "PortAudio error: %s\n", Pa_GetErrorText( err ) ); error2: Pa_Terminate(); pa_active = 0; #ifdef AU_PORTAUDIO_DLL #ifndef PORTAUDIO_V19 free_portaudio_dll(); #endif #endif return -1; }
/////////////////////////////////////////////////////////////////////////////// // MAIN: collect input parameters and run benchmarks /////////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { int info_flag = 0; int usage_flag = 0; int csv_flag = 0; int type_flag = 0; int c; char *sizes_str = NULL; char *devices_str = NULL; char *vector_str = NULL; char *repeat_str = NULL; char *iterations_str = NULL; while (1) { static struct option long_options[] = { /* These options set a flag. */ {"info", no_argument, &info_flag, 1}, {"help", no_argument, &usage_flag, 1}, {"csv", no_argument, &csv_flag, 1}, {"private", no_argument, &type_flag, 1}, {"global", no_argument, &type_flag, 2}, {"local", no_argument, &type_flag, 0}, /* These options don't set a flag. We distinguish them by their indices. */ {"sizes", optional_argument, 0, 'a'}, {"device", optional_argument, 0, 'b'}, {"repeats", optional_argument, 0, 'c'}, {"iterations", optional_argument, 0, 'd'}, {"vector", optional_argument, 0, 'e'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; c = getopt_long (argc, argv, "a:", long_options, &option_index); /* Detect the end of the options. */ if (c == -1) break; switch (c) { case 0: /* If this option set a flag, do nothing else now. */ break; case 'a': sizes_str = optarg; break; case 'b': devices_str = optarg; break; case 'c': repeat_str = optarg; break; case 'd': iterations_str = optarg; break; case 'e': vector_str = optarg; break; case '?': /* getopt_long already printed an error message. */ break; default: abort (); } } // retrieve devices unsigned int num_devices = 0, num_platforms; cl_platform_id* platforms = get_all_platforms(&num_platforms, NULL); cl_device_id* devices = get_all_devices(platforms, num_platforms, &num_devices); free(platforms); if(devices == NULL) { printf("Error: Failed to create a device group!\n"); return 1; } if (info_flag) { print_device_list(devices, num_devices); return 0; } if (usage_flag) { print_usage(); return 0; } // retrieve devices to be benchmarked cl_device_id *used_devices = (cl_device_id*) malloc(sizeof(cl_device_id) * num_devices); unsigned int used_num_devices = 0; if((devices_str == '\0') || (strcmp(devices_str, "all") == 0)) { // nothing specified, run benchmark for all devices for(unsigned int i = 0; i < num_devices; i++) used_devices[i] = devices[i]; used_num_devices = num_devices; } else { // check the given device-numbers and fill up the device-array char* ptr; used_num_devices = 0; ptr = strtok(devices_str, ","); while(ptr != NULL) { unsigned int id = 0; if(sscanf(ptr, "%i", &id) > 0) { if(id >= 0 && id < num_devices) { used_devices[used_num_devices] = devices[id]; used_num_devices++; } } else { printf("invalid device-number given (%d)\n", id); return 1; } ptr = strtok(NULL, ","); } } // retrieve memory-sizes to run the benchmark with -- momentary unused unsigned long* sizes = (unsigned long*) malloc(sizeof(unsigned long) * MAX_SIZES * used_num_devices); for (unsigned int i = 0; i < MAX_SIZES * used_num_devices; i++) { sizes[i] = 0; } unsigned int num_sizes = 0; if(sizes_str == '\0') { // nothing specified, test for maximum num_sizes = 1; for (unsigned int i = 0; i < used_num_devices; i++) { sizes[i * MAX_SIZES] = 10 * 1024 * 1024; } } else { // check given numbers and fill up the device-array char* ptr; ptr = strtok(sizes_str, ","); while(ptr != NULL) { unsigned long size = 0; unsigned long _s; char _m; if (sscanf(ptr, "%lu%c", &_s, &_m) == 2) { switch (_m) { case 'K': case 'k': size = _s * 1024; break; case 'M': case 'm': size = _s * 1024 * 1024; break; default: printf("invalid size given (%s)\n", ptr); return 1; } } else if (sscanf(ptr, "%lu", &_s) > 0) { size = _s; } else { printf("invalid size given (%s)\n", ptr); return 1; } for (unsigned int i = 0; i < used_num_devices; i++) { sizes[num_sizes + i * MAX_SIZES] = size; } num_sizes ++; ptr = strtok(NULL, ","); } } // retrieve amount of repeats for each data-point unsigned int repeats = 0; if (repeat_str == '\0') { repeats = DEFAULT_REPEATS; } else { if (sscanf(repeat_str, "%d", &repeats) > 0) { // nothing more to do } else { printf("invalid number of repeats given (%s)\n", repeat_str); return 1; } } // retrieve amount of iterations used for each data-point unsigned int iterations = 0; if (iterations_str== '\0') { iterations = DEFAULT_ITERATIONS; } else { if (sscanf(iterations_str, "%d", &iterations) > 0) { // nothing more to do } else { printf("invalid number of iterations given (%s)\n", iterations_str); return 1; } } int f4 = 0; char vec[16]; if (vector_str== '\0') { f4 = 0; } else { if (sscanf(vector_str, "%d", &f4) < 0 || f4 < 0 || f4 > 4) { printf("Request for unsupported vector type! Supported are:\n \ \t0 -> float\n \ \t1 -> float2\n \ \t2 -> float4\n \ \t3 -> float8\n \ \t4 -> float16\n"); return 1; } }