Esempio n. 1
0
File: cu2.c Progetto: E-LLP/QuIP
static void init_cu2_devices(QSP_ARG_DECL  Compute_Platform *cpp)
{
	int n_devs,i;

	/* We don't get a proper error message if the cuda files in /dev
	 * are not readable...  So we check that first.
	 */

	check_file_access(QSP_ARG  "/dev/nvidiactl");

	cudaGetDeviceCount(&n_devs);

	if( n_devs == 0 ){
		WARN("No CUDA devices found!?");
		return;
	}

	if( verbose ){
		sprintf(ERROR_STRING,"%d cuda devices found...",n_devs);
		advise(ERROR_STRING);
	}

	default_cuda_dev_name = getenv(DEFAULT_CUDA_ENV_VAR);
	/* may be null */

	for(i=0;i<n_devs;i++){
		char s[32];

		sprintf(s,"/dev/nvidia%d",i);
		check_file_access(QSP_ARG  s);

		init_cu2_device(QSP_ARG  i, cpp);
	}

	if( default_cuda_dev_name == NULL ){
		/* Not specified in environment */
		// reserved var if set in environment?
		assign_var(QSP_ARG  DEFAULT_CUDA_DEV_VAR,first_cuda_dev_name);
		default_cuda_dev_found=1;	// not really necessary?
	} else if( ! default_cuda_dev_found ){
		/* specified incorrectly */
		sprintf(ERROR_STRING, "%s %s not found.\nUsing device %s.",
			DEFAULT_CUDA_DEV_VAR,default_cuda_dev_name,
			first_cuda_dev_name);
		WARN(ERROR_STRING);

		assign_var(QSP_ARG  DEFAULT_CUDA_DEV_VAR,first_cuda_dev_name);
		default_cuda_dev_found=1;	// not really necessary?
	}

	/* hopefully the vector library is already initialized - can we be sure? */

	SET_PLATFORM_FUNCTIONS(cpp,cu2)
	SET_PF_FUNC_TBL(cpp,cu2_vfa_tbl);
	//SET_PLATFORM_DISPATCH_TBL(cpp,cu2_func_tbl);

} // end init_cu2_devices
Esempio n. 2
0
int db_init
	(
	 FF_STD_ARGS_PTR std_args,
	 DATA_BIN_HANDLE dbin_h,
	 int (*error_cb)(int)
	)
{
	FORMAT_DATA_LIST format_data_list = NULL;
	int error = 0;
	int num_errors = 0;
	
	assert(dbin_h);

	if (!dbin_h)
		return(err_push(ERR_API, "NULL DATA_BIN_HANDLE in %s", ROUTINE_NAME));

	if (!*dbin_h)
	{
		*dbin_h = db_make(std_args->input_file ? std_args->input_file : "Application Program");
		if (!*dbin_h)
			return(err_push(ERR_MEM_LACK, "Standard Data Bin"));
	}

	/* Now set the formats and the auxillary files */

	if (db_set(*dbin_h, DBSET_READ_EQV, std_args->input_file))
	{
		err_push(ERR_SET_DBIN, "making name table for %s", std_args->input_file);
		return(DBSET_READ_EQV);
	}
	
	if (db_set(*dbin_h,
	           DBSET_INPUT_FORMATS,
	           std_args->input_file,
	           std_args->output_file,
	           std_args->input_format_file,
	           std_args->input_format_buffer,
	           std_args->input_format_title,
	           &format_data_list
	          )
	   )
	{
		if (format_data_list)
			dll_free_holdings(format_data_list);

		err_push(ERR_SET_DBIN, "setting an input format for %s", std_args->input_file);
		return(DBSET_INPUT_FORMATS);
	}

	num_errors = err_count();

	if (db_set(*dbin_h,
				  DBSET_OUTPUT_FORMATS,
				  std_args->input_file,
				  std_args->output_file,
				  std_args->output_format_file,
				  std_args->output_format_buffer,
				  std_args->output_format_title,
				  &format_data_list
				 )
		)
	{
		if (!error_cb || (*error_cb)(DBSET_OUTPUT_FORMATS))
		{
			dll_free_holdings(format_data_list);

			err_push(ERR_SET_DBIN, "setting an output format for %s", std_args->input_file);
			return(DBSET_OUTPUT_FORMATS);
		}
		else
		{
			while (err_count() > num_errors)
				err_pop();
		}
	}

	error = db_set(*dbin_h, DBSET_CREATE_CONDUITS, std_args, format_data_list);
	dll_free_holdings(format_data_list);
	if (error)
	{
		err_push(ERR_SET_DBIN, "creating array information for %s", std_args->input_file);
		return(DBSET_CREATE_CONDUITS);
	}

	/* Check for variable file */
	if (std_args->var_file)
	{
		FORMAT_DATA_PTR output_fd = fd_get_data(*dbin_h, FFF_OUTPUT);

		if (IS_ARRAY(output_fd->format))
		{
			err_push(ERR_SET_DBIN, "Cannot use variable file with arrays");
			return(DBSET_VARIABLE_RESTRICTION);
		}

		if (db_set(*dbin_h, DBSET_VARIABLE_RESTRICTION, std_args->var_file, output_fd->format))
		{
			err_push(ERR_SET_DBIN, "Unable to use variable file \"%s\"", std_args->var_file);
			return(DBSET_VARIABLE_RESTRICTION);
		}
	}

	if (db_set(*dbin_h, DBSET_EQUATION_VARIABLES))
	{
		err_push(ERR_SET_DBIN, "setting equation variables for %s", std_args->input_file);
		return(DBSET_EQUATION_VARIABLES);
	}

	if (db_set(*dbin_h, DBSET_HEADER_FILE_NAMES, FFF_INPUT, std_args->input_file))
	{
		err_push(ERR_SET_DBIN, "Determining input header file names for %s", std_args->input_file);
		return(DBSET_HEADER_FILE_NAMES);
	}

	num_errors = err_count();

	if (db_set(*dbin_h, DBSET_HEADER_FILE_NAMES, FFF_OUTPUT, std_args->output_file))
	{
		if (!error_cb || (*error_cb)(DBSET_OUTPUT_FORMATS))
		{
			err_push(ERR_SET_DBIN, "Determining output header file names for %s", std_args->output_file);
			return(DBSET_HEADER_FILE_NAMES);
		}
		else
		{
			while (err_count() > num_errors)
				err_pop();
		}
	}

	if (db_set(*dbin_h, DBSET_BYTE_ORDER, FFF_INPUT | FFF_HEADER))
	{
		err_push(ERR_SET_DBIN, "Defining input data byte order");
		return(DBSET_BYTE_ORDER);
	}

	if (db_set(*dbin_h, DBSET_HEADERS))
	{
		err_push(ERR_SET_DBIN, "getting header file for %s", std_args->input_file);
		return(DBSET_HEADERS);
	}
	
	if (db_set(*dbin_h, DBSET_USER_UPDATE_FORMATS))
	{
		err_push(ERR_SET_DBIN, "user update of a format for %s", std_args->input_file);
		return(DBSET_USER_UPDATE_FORMATS);
	}

	if (db_set(*dbin_h, DBSET_BYTE_ORDER, FFF_INPUT))
	{
		err_push(ERR_SET_DBIN, "Defining input data byte order");
		return(DBSET_BYTE_ORDER);
	}

	num_errors = err_count();

	if (db_set(*dbin_h, DBSET_BYTE_ORDER, FFF_OUTPUT))
	{
		if (!error_cb || (*error_cb)(DBSET_OUTPUT_FORMATS))
		{
			err_push(ERR_SET_DBIN, "Defining output data byte order");
			return(DBSET_BYTE_ORDER);
		}
		else
		{
			while (err_count() > num_errors)
				err_pop();
		}
	}

	if (std_args->cache_size == 0)
		std_args->cache_size = DEFAULT_CACHE_SIZE;

	/* Check for query file */
	if (std_args->query_file)
	{
		if (db_set(*dbin_h, DBSET_QUERY_RESTRICTION, std_args->query_file))
		{
			err_push(ERR_GEN_QUERY, "setting query using %s", std_args->query_file);
			return(DBSET_QUERY_RESTRICTION);
		}
	}

	if (db_set(*dbin_h, DBSET_INIT_CONDUITS, FFF_DATA, std_args->records_to_read))
	{
		err_push(ERR_SET_DBIN, "creating array information for %s", std_args->input_file);
		return(DBSET_INIT_CONDUITS);
	}

	if (error)
		return(error);

	error = merge_redundant_conduits((*dbin_h)->array_conduit_list);
	if (error)
		return(error);

	if (fd_get_data(*dbin_h, FFF_INPUT) &&
	    db_set(*dbin_h, DBSET_CACHE_SIZE, std_args->cache_size)
	   )
	{
		return(err_push(ERR_MEM_LACK, "setting data cache for %s", std_args->input_file));
	}

	if (db_set(*dbin_h, DBSET_FORMAT_MAPPINGS))
	{
		err_push(ERR_SET_DBIN, "mapping input to output formats for %s", std_args->input_file);
		return(DBSET_FORMAT_MAPPINGS);
	}

	error = make_unique_format_titles(*dbin_h);
	if (error)
		return ERR_MEM_LACK;

	num_errors = err_count();

	if (db_set(*dbin_h, DBSET_VAR_MINMAX))
	{
		if (!error_cb || (*error_cb)(DBSET_OUTPUT_FORMATS))
		{
			err_push(ERR_SET_DBIN, "setting variable minimums and maximums for %s", std_args->input_file);
			return(DBSET_VAR_MINMAX);
		}
		else
		{
			while (err_count() > num_errors)
				err_pop();
		}
	}
			
	error = check_file_access(*dbin_h);
	if (error)
		return error;

	return(error);
}
Esempio n. 3
0
/** Run the daemon.
 * @param[in] argc Number of arguments in \a argv.
 * @param[in] argv Arguments to program execution.
 */
int main(int argc, char **argv) {
  CurrentTime = time(NULL);

  thisServer.argc = argc;
  thisServer.argv = argv;
  thisServer.uid  = getuid();
  thisServer.euid = geteuid();

#ifdef MDEBUG
  mem_dbg_initialise();
#endif

#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_CORE)
  set_core_limit();
#endif

  umask(077);                   /* better safe than sorry --SRB */
  memset(&me, 0, sizeof(me));
  memset(&me_con, 0, sizeof(me_con));
  cli_connect(&me) = &me_con;
  cli_fd(&me) = -1;

  parse_command_line(argc, argv);

  if (chdir(dpath)) {
    fprintf(stderr, "Fail: Cannot chdir(%s): %s, check DPATH\n", dpath, strerror(errno));
    return 2;
  }

  if (!set_userid_if_needed())
    return 3;

  /* Check paths for accessibility */
  if (!check_file_access(SPATH, 'S', X_OK) ||
      !check_file_access(configfile, 'C', R_OK))
    return 4;

  if (!init_connection_limits())
    return 9;

  close_connections(!(thisServer.bootopt & (BOOT_DEBUG | BOOT_TTY | BOOT_CHKCONF)));

  /* daemon_init() must be before event_init() because kqueue() FDs
   * are, perversely, not inherited across fork().
   */
  daemon_init(thisServer.bootopt & BOOT_TTY);

#ifdef DEBUGMODE
  /* Must reserve fd 2... */
  if (debuglevel >= 0 && !(thisServer.bootopt & BOOT_TTY)) {
    int fd;
    if ((fd = open("/dev/null", O_WRONLY)) < 0) {
      fprintf(stderr, "Unable to open /dev/null (to reserve fd 2): %s\n",
	      strerror(errno));
      return 8;
    }
    if (fd != 2 && dup2(fd, 2) < 0) {
      fprintf(stderr, "Unable to reserve fd 2; dup2 said: %s\n",
	      strerror(errno));
      return 8;
    }
  }
#endif

  event_init(MAXCONNECTIONS);

  setup_signals();
  feature_init(); /* initialize features... */
  log_init(*argv);
  set_nomem_handler(outofmemory);

  initload();
  init_list();
  init_hash();
  init_class();
  initwhowas();
  initmsgtree();
  initstats();

  /* we need this for now, when we're modular this 
     should be removed -- hikari */
  ircd_crypt_init();

  motd_init();

  if (!init_conf()) {
    log_write(LS_SYSTEM, L_CRIT, 0, "Failed to read configuration file %s",
	      configfile);
    return 7;
  }

  if (thisServer.bootopt & BOOT_CHKCONF) {
    if (dbg_client)
      conf_debug_iline(dbg_client);
    fprintf(stderr, "Configuration file %s checked okay.\n", configfile);
    return 0;
  }

  debug_init(thisServer.bootopt & BOOT_TTY);
  if (check_pid()) {
    Debug((DEBUG_FATAL, "Failed to acquire PID file lock after fork"));
    exit(2);
  }

  init_server_identity();

  uping_init();

  stats_init();

  IPcheck_init();
  timer_add(timer_init(&connect_timer), try_connections, 0, TT_RELATIVE, 1);
  timer_add(timer_init(&ping_timer), check_pings, 0, TT_RELATIVE, 1);
  timer_add(timer_init(&destruct_event_timer), exec_expired_destruct_events, 0, TT_PERIODIC, 60);
  timer_add(timer_init(&mute_timer), check_expired_mutes, 0, TT_PERIODIC, 30);

  CurrentTime = time(NULL);

  SetMe(&me);
  cli_magic(&me) = CLIENT_MAGIC;
  cli_from(&me) = &me;
  make_server(&me);

  cli_serv(&me)->timestamp = TStime();  /* Abuse own link timestamp as start TS */
  cli_serv(&me)->prot      = atoi(MAJOR_PROTOCOL);
  cli_serv(&me)->up        = &me;
  cli_serv(&me)->down      = NULL;
  cli_handler(&me)         = SERVER_HANDLER;

  SetYXXCapacity(&me, MAXCLIENTS);

  cli_lasttime(&me) = cli_since(&me) = cli_firsttime(&me) = CurrentTime;

  hAddClient(&me);

  write_pidfile();
  init_counters();

  Debug((DEBUG_NOTICE, "Server ready..."));
  log_write(LS_SYSTEM, L_NOTICE, 0, "Server Ready");

  event_loop();

  return 0;
}