Ejemplo n.º 1
0
int initialize_kernels(const unsigned char *code, int codeLen,
                       handle_t *module_ptr) {
    elf_t *lib = obj_dlopen_mem(code, codeLen);
    if (!lib) {
        halide_print(NULL, "dlopen_mem failed\n");
        return -1;
    }

    // Initialize the runtime. The Hexagon runtime can't call any
    // system functions (because we can't link them), so we put all
    // the implementations that need to do so here, and pass poiners
    // to them in here.
    set_runtime_t set_runtime = (set_runtime_t)obj_dlsym(lib, "halide_noos_set_runtime");
    if (!set_runtime) {
        obj_dlclose(lib);
        halide_print(NULL, "halide_noos_set_runtime not found in shared object\n");
        return -1;
    }

    int result = set_runtime(halide_malloc,
                             halide_free,
                             halide_print,
                             halide_error,
                             halide_do_par_for,
                             halide_do_task,
                             halide_get_symbol,
                             halide_load_library,
                             halide_get_library_symbol);
    if (result != 0) {
        obj_dlclose(lib);
        halide_print(NULL, "set_runtime failed\n");
        return result;
    }
    *module_ptr = reinterpret_cast<handle_t>(lib);

    return 0;
}
Ejemplo n.º 2
0
  void function_minimizer::computations1(int argc,char * argv[])
  {
    tracing_message(traceflag,"B1");

    int on=-1;
    int nopt=-1;
#if defined(USE_ADPVM)
    if (ad_comm::pvm_manager)
    {
      switch (ad_comm::pvm_manager->mode)
      {
      case 1: //master
        pvm_params::send_all_to_slaves();
        break;
      case 2: //slave
        pvm_params::get_all_from_master();
        break;
      default:
        cerr << "Illegal value for ad_comm::pvm_manager->mode"
         " value was " << ad_comm::pvm_manager->mode << endl;
        ad_exit(1);
      }
    }
#endif  // #if defined(USE_ADPVM)

    set_runtime();

    if ( (on=option_match(argc,argv,"-hbf",nopt))>-1)
    {
      gradient_structure::Hybrid_bounded_flag=1;
    }

    // Sets the maximum number of function evaluation as determined from the
    // command line
    if ( (on=option_match(argc,argv,"-maxfn",nopt))>-1)
    {
      if (nopt ==1)
      {
        set_runtime_maxfn(argv[on+1]);
      }
      else
      {
        cerr << "Wrong number of options to -mafxn -- must be 1"
          " you have " << nopt << endl;
      }
    }

    if ( (on=option_match(argc,argv,"-ttr",nopt))>-1)
    {
      test_trust_flag=1;
    }

    if ( (on=option_match(argc,argv,"-crit",nopt))>-1)
    {
      if (nopt ==1)
      {
        set_runtime_crit(argv[on+1]);
      }
      else
      {
        cerr << "Wrong number of options to -crit -- must be 1"
          " you have " << nopt << endl;
      }
    }

    stddev_params::get_stddev_number_offset();

    tracing_message(traceflag,"C1");

    repeatminflag=0;
    do
    {
     /*
      if (spminflag)
      {
        repeatminflag=1;
        spminflag=0;
      }
      else
      {
        repeatminflag=0;
      }
      */

      if (option_match(argc,argv,"-noest") == -1)
      {
        if (!function_minimizer::have_constraints)
        {
          minimize();
        }
        else
        {
          constraints_minimize();
        }
      }
      else
      {
        initial_params::current_phase=initial_params::max_number_phases;
      }
      tracing_message(traceflag,"D1");

      //double ratio=100.*gradient_structure::max_last_offset/12000.0;
      tracing_message(traceflag,"E1");
      if (option_match(argc,argv,"-est") == -1)
      {
        if (!quit_flag)
        {
          // save the sparse Hessian for the random effects
          if (lapprox && lapprox->sparse_hessian_flag)
          {
            if (lapprox->sparse_triplet2)
            {
              dcompressed_triplet& dct=*(lapprox->sparse_triplet2);
              adstring tmpstring = ad_comm::adprogram_name + ".shess";
              uostream uos((char*)(tmpstring));
              uos << dct.get_n()  << dct.indexmin() << dct.indexmax()
                  << dct.get_coords() << dct.get_x();
            }
          }

          on=option_match(argc,argv,"-nohess");
          int on1=option_match(argc,argv,"-noest");
          if (on==-1 && on1==-1)
          {
            if (option_match(argc,argv,"-sdonly")==-1)
            {
              hess_routine();
            }
            // set this flag so that variables only needed for their std devs
            // will be calculated
            initial_params::sd_phase=1;
#if defined(USE_ADPVM)
            if (ad_comm::pvm_manager)
            {
              if (ad_comm::pvm_manager->mode==1)  //master
              {
                depvars_routine();
                hess_inv();
                if (spminflag==0)
                {
                  sd_routine();
                }
              }
            }
            else
#endif
            {
              depvars_routine();
              hess_inv();
              if (spminflag==0)
              {
                sd_routine();
              }
            }
          }
          else
          {
            initial_params::sd_phase=1;
          }
          if (spminflag==0)
          {
            if ( (on=option_match(argc,argv,"-lprof"))>-1)
            {
              if (likeprof_params::num_likeprof_params)
              {
    #if defined(USE_ADPVM)
                if (ad_comm::pvm_manager)
                {
                  switch (ad_comm::pvm_manager->mode)
                  {
                  case 1: // master
                    likeprof_routine(ffbest);
                    break;
                  case 2: // slave
                    pvm_slave_likeprof_routine();
                    break;
                  default:
                    cerr << "error illega value for pvm_manager->mode" << endl;
                    exit(1);
                  }
                }
                else
    #endif
                {
                  const double f = value(*objective_function_value::pobjfun);
                  likeprof_routine(f);
                }
              }
            }
            nopt=0;
            int on2=-1;
            int nopt2=-1;

            // stuff for mcmc
            //cout << "checking for mcmc" << endl;
            if ( (on=option_match(argc,argv,"-mcmc",nopt))>-1 ||
                 (on=option_match(argc,argv,"-mcmc2",nopt))>-1)
            {
              if ( (on2=option_match(argc,argv,"-mcmc2",nopt2))>-1)
                mcmc2_flag=1;
              else
                mcmc2_flag=0;

 #if defined(USE_ADPVM)
              if (ad_comm::pvm_manager)
              {
                switch (ad_comm::pvm_manager->mode)
                {
                case 1: // master
                  pvm_master_mcmc_computations();
                break;
                case 2: // slave
                  pvm_slave_mcmc_routine();
                  break;
                default:
                  cerr << "error illega value for pvm_manager->mode" << endl;
                  exit(1);
                }
              }
              else
 #endif
              {
                mcmc_computations();
              }
            }
            if ( (on=option_match(argc,argv,"-sob",nopt))>-1)
            {
              int nsob=0;
              //int iseed0=0;
              //double dscale=1.0;
              if (nopt)
              {
                nsob=atoi(argv[on+1]);
                if (nsob <=0)
                {
                  cerr << " Invalid option following command line option -sob"
                          " -- "
                    << endl << " ignored" << endl;
                }
              }
              if ( (on=option_match(argc,argv,"-mcr",nopt))>-1)
              {
                //sob_routine(nsob,dscale,1);
                //sobol_importance_routine(nsob,iseed0,dscale,1);
              }
              else
              {
                //sobol_importance_routine(nsob,iseed0,dscale,0);
              }
            }
            initial_params::sd_phase=0;
          }
        }
      }
    }
    while(spminflag || repeatminflag);
  }