static void on_client_connect(int client_idx)
{
	struct rte_mbuf *buffer = get_buffer();
	if(!buffer) {
		return;
	}
	unsigned char *data = rte_pktmbuf_mtod(buffer, unsigned char *);
	*data = IPAUGENBLICK_NEW_IFACES;
	data++;
	rte_pktmbuf_data_len(buffer) = get_all_devices(data) + 1;
	rte_ring_enqueue(ipaugenblick_clients[client_idx].client_ring,(void *)buffer);
	buffer = get_buffer();
	if(!buffer) {
		return;
	}
	data = rte_pktmbuf_mtod(buffer, unsigned char *);
	*data = IPAUGENBLICK_NEW_ADDRESSES;
	data++;
	rte_pktmbuf_data_len(buffer) = get_all_addresses(data) + 1;
	rte_ring_enqueue(ipaugenblick_clients[client_idx].client_ring,(void *)buffer);
	buffer = get_buffer();
	if(!buffer) {
		return;
	}
	data = rte_pktmbuf_mtod(buffer, unsigned char *);
	*data = IPAUGENBLICK_END_OF_RECORD;
	rte_ring_enqueue(ipaugenblick_clients[client_idx].client_ring,(void *)buffer);
}
Пример #2
0
static SynceInfo* synce_info_from_midasyncd(const char* path)
{
  bool success = false;
  SynceInfo* result = calloc(1, sizeof(SynceInfo));
  DBusConnection* connection = NULL;
  DBusError error;
  char** device_names = NULL;
  int device_count = 0;
  DBusMessage* properties = NULL;

  dbus_error_init(&error);

  /* Connect to D-BUS */
  connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
  if (dbus_error_is_set (&error))
  {
    synce_error("%s error '%s'", error.name, error.message);
    dbus_error_free(&error);
    goto exit;
  }

  if (!connection) {
    synce_error("Failed to connect to the D-BUS daemon");
    goto exit;
  }

  if (!path)
  {
    if (!get_all_devices(connection, &device_names, &device_count))
      goto exit;

    if (device_count < 1)
      goto exit;

    path = device_names[0];
  }

  if (!get_all_properties(connection, path, &properties))
    goto exit;

  if (!properties_to_info(properties, result))
    goto exit;

  success = true;

exit:
  /* TODO: clean up D-BUS connection */
  if (device_names)
    dbus_free_string_array(device_names);

  if (success)
    return result;
  else
  {
    synce_info_destroy(result);
    return NULL;
  }
}
Пример #3
0
static int preprocess_batch(BATCH batch )

{
    int iStatus;
    int count;
    static char * this_func = "preprocess_batch";
    char szSet[256];
    
    (void)arb_put_state(dbproc,ARB_STATUS_PREPROC);
    
    /* Lock files */
    sprintf(szSet, "   SET dispatch_status = %d ", BID_IN_PROGRESS);
    count = set_bill_files(szSet, NULL, batch->batch_id,
			   bid_hold_flag, bid_error_flag,
			   RERUN ? BID_COMPLETE : BID_NOT_STARTED);

    if (count < 0)
	return(count);
	
    if (0 == count)
    {
	emit(BIDMOD,BID_NO_FILES,this_func);
	return(BID_NO_FILES);
    }

    /* Lock all available devices for BID that PRINTs */
    /* Don't need to lock devices for BID that FTPs  LLT */

    if (!BID_ftp)
    {
    	get_all_devices(bid_queueDevices);            /* depends on DISPATCH_TYPE */
    	if (0 >= QueueCount(bid_queueDevices))
    	{
   	    emit(BIDMOD,BID_NO_FIND_DEV_TYPE,this_func,DISPATCH_TYPE);
	    return(-1);
    	}
    
    	lock_all_devices();           /* result -->> bid_queueDevicesLocked */
    	if (0 >= QueueCount(bid_queueDevicesLocked))
    	{
	    emit(BIDMOD,BID_NO_LOCK_DEV_TYPE,this_func,DISPATCH_TYPE);
	    return(-1);
    	}
    }

    /* Get list of files in this batch. -->> bid_queueFiles */
    if (SUCCESS != (iStatus = get_file_list(bid_queueFiles, batch->batch_id,
					bid_hold_flag, bid_error_flag)))
   	return(iStatus);
    count = QueueCount(bid_queueFiles);
    emit(BIDMOD,BID_NUM_FILES_BATCH,this_func,count);
    if (count)
  	return(SUCCESS);
    else
  	return(NO_BILL_FILES);
}
Пример #4
0
int main(int argc, char **argv)
{
	int csv_flag = 0;
	unsigned int num_devices = 0, num_platforms = 0;
	cl_device_id *devices;
	int i = 0, j = 0;
	int err;
	double duration;
	double delta;

	int ret;
	int device_id;
	int plattform_id;

	static struct option long_options[] = 
	{
		{"csv",  no_argument,       &csv_flag, 1},
		{"device",  required_argument, 0, 'a'},
		{0, 0, 0, 0}
	};

	if(argc < 3)
		show_help(argv[0]);

	while(1){
		int option_index = 0;
		int c = getopt_long(argc, argv, "", long_options, &option_index);	

		if(c == -1)
			break;

		switch(c){
			case 0:
				break;
			case 'a':
				ret = sscanf(optarg, "%i", &device_id);
				plattform_id = 0;
				if(ret < 1 || plattform_id < 0 || device_id < -1)
					show_help(argv[0]);

				if(plattform_id > 0){
					fprintf(stderr, "sorry, changing the platform is currently not supported\n");
					exit(1);
				}

				break;
			case '?':
				break;
			default:
				abort();
		}
	}


    cl_platform_id* platforms = get_all_platforms(&num_platforms, NULL);
	devices = get_all_devices(platforms, num_platforms, &num_devices);
    free(platforms);
//	devices = get_all_devices(&num_devices);
//  	cl_device_id* devices = get_device_by_platform(&num_devices, 1);

    if(devices == NULL){
		fprintf(stderr, "get_all_devices() failed!\n");
		return 1;
	}

    int lower_id = 0, upper_id = 0;

    if(device_id == -1)
    {
        lower_id = 0;
        upper_id = num_devices;
    }
    else
    {
        lower_id = device_id;
        upper_id = device_id + 1;
    }

	if(csv_flag) {
		printf("#bm: %s, %s\n", BM_NAME, BM_VERSION);
		printf("#spec: args:unsigned, loc:unsigned, compile_time:double, invocation_time:double, delta:double\n");
	} else {
 		printf("# <cur_test>, <total_tests>, <args>, <loc>, <compile time (ms)>, <duration (ms)>, <delta (ms)>\n");
	}

	for(device_id = lower_id; device_id < upper_id; ++device_id){

		if(device_id > (int)num_devices){
			fprintf(stderr, "invalid device id!\n");
			exit(1);
		}

		if(!csv_flag) print_short_device_info(devices[device_id], i);
		else print_csv_device_info(devices[device_id]);
	
		cl_context context = clCreateContext(NULL, 1, &devices[device_id], NULL, NULL, &err);
		if(!context){
			fprintf(stderr, "clCreateContext() failed!\n");
			fprintf(stderr, "err: %i\n", err);
			return -1;
		}

		cl_command_queue commands = clCreateCommandQueue(context, devices[device_id], CL_QUEUE_PROFILING_ENABLE, &err);
		if(!commands){
			fprintf(stderr, "clCreateCommandQueue() failed!\n");
			fprintf(stderr, "err: %s\n", oclErrorString(err));
			return -1;
		}

		int avgLoc = 0;
		double compile = 0.0, avgCompile = 0.0, avgDuration = 0.0, avgDelta = 0.0;

		j = sizeof(ki_tests)/sizeof(struct _test_case);

		for(i = 0; i < j; i++){
			if(run_kernel_benchmark<float>(devices[device_id], context, commands, ki_tests[i].kernel_args, ki_tests[i].kernel_loc, &duration, &delta, &compile) < 0){
				fprintf(stderr, "run_kernel_benchmark() failed!\n");
				return 1;
			}
			avgLoc += ki_tests[i].kernel_loc;
			avgCompile += compile;
			avgDuration += duration;
			avgDelta += delta;
			if(csv_flag) printf("%8i,%8i,%10.4lf,%10.4lf,%10.4lf\n", i + 1, j, ki_tests[i].kernel_args, ki_tests[i].kernel_loc, compile ,duration, delta);
			else printf("%8i,%8i,%8i,%8i,%10.4lf,%10.4lf,%10.4lf\n", i + 1, j, ki_tests[i].kernel_args, ki_tests[i].kernel_loc, compile ,duration, delta);
			fflush(stdout);
		}

		if(!csv_flag) printf("avg,%i,-,%i,%f,%f,%f\n", j, avgLoc/j, avgCompile/j, avgDuration/j, avgDelta/j);

		clReleaseContext(context);
		clReleaseCommandQueue(commands);
	}

	return 0;
}
Пример #5
0
///////////////////////////////////////////////////////////////////////////////
//  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;
        }
    }