Example #1
0
  bool solveP_( vector< Coef >& x )
  {
    Coef res, res0;

    if ( is_trivial( b_ ) )
    {
      x = b_;

      return true;
    }

    r_ = b_ - A_ * x;
    res = res0 = sync_norm( r_ );
    if ( is_trivial( res0 ) ) return true;

    for ( int i = 0; i < A_.m(); ++i )
    {
      bool converged = false;
      Coef norm;
      
      norm = x * x;
#ifdef ELAI_DEBUG
      std::cerr << " ||x||=" << norm
                << " ||Ax-b||=" << res
                << "  " << res / res0 << std::endl;
#endif
      if ( std::isnan( res ) ) return false;
      else if ( rel_converged( res, res0 ) || abs_converged( res ) ) converged = true;
      else if ( !is_trivial( norm ) && rel_converged( res, norm ) ) converged = true;

      if ( isOK( converged ) ) return true;

      // Preconditionng:
      ELAI_PROF_BEG( prec_elapsed_ );
      P_->forward( x );
      P_->backward( x );
      ELAI_SYNC( x );
      ELAI_PROF_END( prec_elapsed_ );

      for ( int i = 0; i < iter_max(); ++i )
      {
        Coef a = 1. / A_( i, i );
        y_( i ) = a * y_( i ) + x( i );
      }
      ELAI_SYNC( y_ );
      x = y_;

      r_ = b_ - A_ * x;
      res = sync_norm( r_ );
    }

    return false;
  }
Example #2
0
  bool solve_( vector< Coef >& x )
  {
    Coef res, res0;

    if ( is_trivial( b_ ) )
    {
      x = b_;

      return true;
    }

    r_ = b_ - A_ * x;
    res = res0 = sync_norm( r_ );
    if ( is_trivial( res0 ) ) return true;

    for ( int i = 0; i < iter_max(); ++i )
    {
      bool converged = false;
      Coef norm;
      
      norm = x * x;
#ifdef ELAI_DEBUG
      std::cerr << " ||x||=" << norm
                << " ||Ax-b||=" << res
                << "  " << res / res0 << std::endl;
#endif
      if ( std::isnan( res ) ) return false;
      else if ( rel_converged( res, res0 ) || abs_converged( res ) ) converged = true;
      else if ( !is_trivial( norm ) && rel_converged( res, norm ) ) converged = true;

      if ( isOK( converged ) ) return true;

      for ( int i = 0; i < A_.m(); ++i )
      {
        Coef a = 1. / A_( i, i );
        r_( i ) = a * r_( i ) + x( i );
      }
      ELAI_SYNC( r_ );
      x = r_;

      r_ = b_ - A_ * x;
      res = sync_norm( r_ );
    }

    return false;
  }
Example #3
0
// Determine is a method is mature.
bool SimpleThresholdPolicy::is_mature(Method* method) {
  if (is_trivial(method)) return true;
  MethodData* mdo = method->method_data();
  if (mdo != NULL) {
    int i = mdo->invocation_count();
    int b = mdo->backedge_count();
    double k = ProfileMaturityPercentage / 100.0;
    return call_predicate_helper<CompLevel_full_profile>(i, b, k, method) ||
           loop_predicate_helper<CompLevel_full_profile>(i, b, k, method);
  }
  return false;
}
Example #4
0
// Common transition function. Given a predicate determines if a method should transition to another level.
CompLevel SimpleThresholdPolicy::common(Predicate p, Method* method, CompLevel cur_level) {
  CompLevel next_level = cur_level;
  int i = method->invocation_count();
  int b = method->backedge_count();

  if (is_trivial(method) && cur_level != CompLevel_aot) {
    next_level = CompLevel_simple;
  } else {
    switch(cur_level) {
    case CompLevel_aot: {
      if ((this->*p)(i, b, cur_level, method)) {
        next_level = CompLevel_full_profile;
      }
    }
    break;
    case CompLevel_none:
      // If we were at full profile level, would we switch to full opt?
      if (common(p, method, CompLevel_full_profile) == CompLevel_full_optimization) {
        next_level = CompLevel_full_optimization;
      } else if ((this->*p)(i, b, cur_level, method)) {
        next_level = CompLevel_full_profile;
      }
      break;
    case CompLevel_limited_profile:
    case CompLevel_full_profile:
      {
        MethodData* mdo = method->method_data();
        if (mdo != NULL) {
          if (mdo->would_profile()) {
            int mdo_i = mdo->invocation_count_delta();
            int mdo_b = mdo->backedge_count_delta();
            if ((this->*p)(mdo_i, mdo_b, cur_level, method)) {
              next_level = CompLevel_full_optimization;
            }
          } else {
            next_level = CompLevel_full_optimization;
          }
        }
      }
      break;
    }
  }
  return MIN2(next_level, (CompLevel)TieredStopAtLevel);
}
Example #5
0
// Common transition function. Given a predicate determines if a method should transition to another level.
CompLevel AdvancedThresholdPolicy::common(Predicate p, methodOop method, CompLevel cur_level) {
  if (is_trivial(method)) return CompLevel_simple;

  CompLevel next_level = cur_level;
  int i = method->invocation_count();
  int b = method->backedge_count();

  switch(cur_level) {
  case CompLevel_none:
    // If we were at full profile level, would we switch to full opt?
    if (common(p, method, CompLevel_full_profile) == CompLevel_full_optimization) {
      next_level = CompLevel_full_optimization;
    } else if ((this->*p)(i, b, cur_level)) {
      // C1-generated fully profiled code is about 30% slower than the limited profile
      // code that has only invocation and backedge counters. The observation is that
      // if C2 queue is large enough we can spend too much time in the fully profiled code
      // while waiting for C2 to pick the method from the queue. To alleviate this problem
      // we introduce a feedback on the C2 queue size. If the C2 queue is sufficiently long
      // we choose to compile a limited profiled version and then recompile with full profiling
      // when the load on C2 goes down.
      if (CompileBroker::queue_size(CompLevel_full_optimization) >
          Tier3DelayOn * compiler_count(CompLevel_full_optimization)) {
        next_level = CompLevel_limited_profile;
      } else {
        next_level = CompLevel_full_profile;
      }
    }
    break;
  case CompLevel_limited_profile:
    if (is_method_profiled(method)) {
      // Special case: we got here because this method was fully profiled in the interpreter.
      next_level = CompLevel_full_optimization;
    } else {
      methodDataOop mdo = method->method_data();
      if (mdo != NULL) {
        if (mdo->would_profile()) {
          if (CompileBroker::queue_size(CompLevel_full_optimization) <=
              Tier3DelayOff * compiler_count(CompLevel_full_optimization) &&
              (this->*p)(i, b, cur_level)) {
            next_level = CompLevel_full_profile;
          }
        } else {
          next_level = CompLevel_full_optimization;
        }
      }
    }
    break;
  case CompLevel_full_profile:
    {
      methodDataOop mdo = method->method_data();
      if (mdo != NULL) {
        if (mdo->would_profile()) {
          int mdo_i = mdo->invocation_count_delta();
          int mdo_b = mdo->backedge_count_delta();
          if ((this->*p)(mdo_i, mdo_b, cur_level)) {
            next_level = CompLevel_full_optimization;
          }
        } else {
          next_level = CompLevel_full_optimization;
        }
      }
    }
    break;
  }
  return next_level;
}
// Common transition function. Given a predicate determines if a method should transition to another level.
CompLevel AdvancedThresholdPolicy::common(Predicate p, Method* method, CompLevel cur_level, bool disable_feedback) {
  CompLevel next_level = cur_level;
  int i = method->invocation_count();
  int b = method->backedge_count();

  if (is_trivial(method)) {
    next_level = CompLevel_simple;
  } else {
    switch(cur_level) {
    case CompLevel_none:
      // If we were at full profile level, would we switch to full opt?
      if (common(p, method, CompLevel_full_profile, disable_feedback) == CompLevel_full_optimization) {
        next_level = CompLevel_full_optimization;
      } else if ((this->*p)(i, b, cur_level, method)) {
#if INCLUDE_JVMCI
        if (UseJVMCICompiler) {
          // Since JVMCI takes a while to warm up, its queue inevitably backs up during
          // early VM execution.
          next_level = CompLevel_full_profile;
          break;
        }
#endif
        // C1-generated fully profiled code is about 30% slower than the limited profile
        // code that has only invocation and backedge counters. The observation is that
        // if C2 queue is large enough we can spend too much time in the fully profiled code
        // while waiting for C2 to pick the method from the queue. To alleviate this problem
        // we introduce a feedback on the C2 queue size. If the C2 queue is sufficiently long
        // we choose to compile a limited profiled version and then recompile with full profiling
        // when the load on C2 goes down.
        if (!disable_feedback && CompileBroker::queue_size(CompLevel_full_optimization) >
            Tier3DelayOn * compiler_count(CompLevel_full_optimization)) {
          next_level = CompLevel_limited_profile;
        } else {
          next_level = CompLevel_full_profile;
        }
      }
      break;
    case CompLevel_limited_profile:
      if (is_method_profiled(method)) {
        // Special case: we got here because this method was fully profiled in the interpreter.
        next_level = CompLevel_full_optimization;
      } else {
        MethodData* mdo = method->method_data();
        if (mdo != NULL) {
          if (mdo->would_profile()) {
            if (disable_feedback || (CompileBroker::queue_size(CompLevel_full_optimization) <=
                                     Tier3DelayOff * compiler_count(CompLevel_full_optimization) &&
                                     (this->*p)(i, b, cur_level, method))) {
              next_level = CompLevel_full_profile;
            }
          } else {
            next_level = CompLevel_full_optimization;
          }
        }
      }
      break;
    case CompLevel_full_profile:
      {
        MethodData* mdo = method->method_data();
        if (mdo != NULL) {
          if (mdo->would_profile()) {
            int mdo_i = mdo->invocation_count_delta();
            int mdo_b = mdo->backedge_count_delta();
            if ((this->*p)(mdo_i, mdo_b, cur_level, method)) {
              next_level = CompLevel_full_optimization;
            }
          } else {
            next_level = CompLevel_full_optimization;
          }
        }
      }
      break;
    }
  }
  return MIN2(next_level, (CompLevel)TieredStopAtLevel);
}
Example #7
0
  bool solve_( vector< Coef >& x )
  {
    Coef res, res0;

    if ( is_trivial( b_ ) )
    {
      x = b_;

      return true;
    }

    r_ = b_ - A_ * x;
    res = res0 = sync_norm( r_ );
    if ( is_trivial( res0 ) ) return true;

    rs0_ = r_;
    p_ = r_;

    for ( int i = 0; i < iter_max(); ++i )
    {
      bool converged = false;
      Coef alpha, beta, omega, tmp1, tmp2;

      Coef norm = x * x;
#ifdef ELAI_DEBUG
      std::cerr << " ||x||=" << norm
                << " ||Ax-b||=" << res
                << "  " << res / res0 << std::endl;
#endif
      if ( std::isnan( res ) ) return false;
      else if ( rel_converged( res, res0 ) || abs_converged( res ) ) converged = true;
      else if ( !is_trivial( norm ) && rel_converged( res, norm ) ) converged = true;

      if ( isOK( converged ) ) return true;

      Ap_ = A_ * p_;
      ELAI_SYNC( Ap_ );

      ELAI_PROD( tmp1, rs0_, r_ );
      ELAI_PROD( tmp2, rs0_, Ap_ );

      // This avoidance for numerical breakdowns is NOT good.
      // However we have not implemented any other strategies.
      if ( sqrt( fabs( tmp2 ) ) / res0 <= bthres_ ) tmp2 = rs0_ * rs0_;

      alpha = tmp1 / tmp2;
      s_ = r_ - alpha * Ap_;

      s1_ = A_ * s_;
      ELAI_SYNC( s1_ );

      ELAI_PROD( tmp1, s1_, s_ );
      ELAI_PROD( tmp2, s1_, s1_ );

      omega = tmp1 / tmp2;
      x = x + alpha * p_ + omega * s_;

      r1_ = s_ - omega * s1_;

      ELAI_PROD( tmp1, rs0_, r1_ );
      ELAI_PROD( tmp2, rs0_, r_ );

      beta = alpha / omega * tmp1 / tmp2;
      p_ = r1_ + beta * ( p_ - omega * Ap_ );

      r_ = r1_;
      res = fix_norm( r_ );
    }

    return false;
  }
Example #8
0
bool
RoutePlanner::solve(const AGeoPoint& origin,
                    const AGeoPoint& destination,
                    const RoutePlannerConfig& config,
                    const short h_ceiling)
{
  on_solve(origin, destination);
  rpolars_route.set_config(config, std::max(destination.altitude, origin.altitude),
                           h_ceiling);
  rpolars_reach.set_config(config, std::max(destination.altitude, origin.altitude),
                           h_ceiling);

  m_reach_polar_mode = config.reach_polar_mode;

  {
    const AFlatGeoPoint s_origin(task_projection.project(origin), origin.altitude);
    const AFlatGeoPoint s_destination(task_projection.project(destination), destination.altitude);

    if (!(s_origin == origin_last) || !(s_destination == destination_last))
      dirty = true;

    if (is_trivial())
      return false;

    dirty = false;
    origin_last = s_origin;
    destination_last = s_destination;

    h_min = std::min(s_origin.altitude, s_destination.altitude);
    h_max = rpolars_route.cruise_altitude;
  }

  solution_route.clear();
  solution_route.push_back(origin);
  solution_route.push_back(destination);

  if (!rpolars_route.terrain_enabled() && !rpolars_route.airspace_enabled())
    return false; // trivial

  m_search_hull.clear();
  m_search_hull.push_back(SearchPoint(origin_last, task_projection));

  RoutePoint start = origin_last;
  m_astar_goal = destination_last;

  RouteLink e_test(start, m_astar_goal, task_projection);
  if (e_test.is_short())
    return false;
  if (!rpolars_route.achievable(e_test))
    return false;

  count_dij=0;
  count_airspace=0;
  count_terrain=0;
  count_supressed=0;

  bool retval = false;
  m_planner.restart(start);

  unsigned best_d = UINT_MAX;

  if (verbose) {
    printf("# goal node (%d,%d,%d)\n",
           m_astar_goal.Longitude, m_astar_goal.Latitude, m_astar_goal.altitude);
    printf("# start node (%d,%d,%d)\n",
           start.Longitude, start.Latitude, start.altitude);
  }

  while (!m_planner.empty()) {
    const RoutePoint node = m_planner.pop();

    if (verbose>1) {
      printf("# processing node (%d,%d,%d)  %d,%d  q size %d\n",
             node.Longitude, node.Latitude, node.altitude,
             m_planner.get_node_value(node).g,
             m_planner.get_node_value(node).h,
             m_planner.queue_size());
    }

    h_min = std::min(h_min, node.altitude);
    h_max = std::max(h_max, node.altitude);

    bool is_final = (node == m_astar_goal);
    if (is_final) {
      if (!retval)
        best_d = UINT_MAX;
      retval = true;
    }

    if (is_final) // @todo: allow fallback if failed
    { // copy improving solutions
      Route this_solution;
      unsigned d = find_solution(node, this_solution);
      if (d< best_d) {
        best_d = d;
        solution_route = this_solution;
      }
    }

    if (retval)
      break; // want top solution only

    // shoot for final
    RouteLink e(node, m_astar_goal, task_projection);
    if (set_unique(e))
      add_edges(e);

    while (!m_links.empty()) {
      add_edges(m_links.front());
      m_links.pop();
    }

  }
  count_unique = m_unique.size();

  if (retval && verbose) {
    printf("# solved with %d intermediate points\n", (int)(solution_route.size()-2));
  }

  if (retval) {
    // correct solution for rounding
    assert(solution_route.size()>=2);
    for (unsigned i=0; i< solution_route.size(); ++i) {
      FlatGeoPoint p(task_projection.project(solution_route[i]));
      if (p== origin_last) {
        solution_route[i] = AGeoPoint(origin, solution_route[i].altitude);
      } else if (p== destination_last) {
        solution_route[i] = AGeoPoint(destination, solution_route[i].altitude);
      }
    }

  } else {
    solution_route.clear();
    solution_route.push_back(origin);
    solution_route.push_back(destination);
  }

  m_planner.clear();
  m_unique.clear();
//  m_search_hull.clear();
  return retval;
}