Пример #1
0
 wpath_traits::internal_string_type
 wpath_traits::to_internal( const external_string_type & src )
 {
   locked = true;
   std::size_t work_size( src.size()+1 );
   boost::scoped_array<wchar_t> work( new wchar_t[ work_size ] );
   std::mbstate_t state  = std::mbstate_t();  // perhaps unneeded, but cuts bug reports
   const external_string_type::value_type * from_next;
   internal_string_type::value_type * to_next;
   if ( converter()->in( 
     state, src.c_str(), src.c_str()+src.size(), from_next, work.get(),
     work.get()+work_size, to_next ) != std::codecvt_base::ok )
     boost::throw_exception( boost::filesystem::wfilesystem_error(
       "boost::filesystem::wpath::to_internal conversion error",
       system::error_code( system::posix::invalid_argument, system::system_category ) ) );
   *to_next = L'\0';
   return internal_string_type( work.get() );
 }
Пример #2
0
 mbpath_traits::internal_string_type 
 mbpath_traits::to_internal( const external_string_type & src )
 {
     std::size_t work_size( src.size()+1 );
     boost::scoped_array<wchar_t> work( new wchar_t[ work_size ] );
     std::mbstate_t state;
     const external_string_type::value_type * from_next;
     internal_string_type::value_type * to_next;
     if ( cvt->in( 
       state, src.c_str(), src.c_str()+src.size(), from_next, work.get(),
       work.get()+work_size, to_next ) != std::codecvt_base::ok )
       boost::throw_exception<fs::basic_filesystem_error<mbpath> >(
         fs::basic_filesystem_error<mbpath>(
           "user::mbpath::to_internal conversion error",
           boost::system::error_code( EINVAL, boost::system::errno_ecat ) ) );
     *to_next = L'\0';
     return internal_string_type( work.get() );
 }
Пример #3
0
void LibDNNBlas<MItype, MOtype>::scale(const uint_tp n,
           const MItype alpha, vptr<const MItype> x, vptr<MOtype> y,
           const QuantizerValues* const alpha_quant,
           const QuantizerValues* const x_quant,
           const QuantizerValues* const y_quant) {
  string identifier = scale_string_identifier();

  int_tp id = get_id(identifier);
  if (id < 0) {
    id = get_id_or_new(identifier);
  }
  shared_ptr<LibDNNTuner> tuner = program_tuners_[id];
  shared_ptr<DeviceProgram> program = programs_[id];
  boost::shared_lock<boost::shared_mutex> lock(program_mutex_);
  if (!program_ready_[id]) {
    lock.unlock();
    // Compiling new kernel has to lock the program lock exclusively
    boost::unique_lock<boost::shared_mutex> ulock(program_mutex_);
    if (!program_ready_[id]) {
      stringstream ss;
      ss << generate_scale_source(program, tuner);
      program->set_source(ss.str());
      program->Compile(true, true);
      program_ready_[id] = true;
    }
    ulock.unlock();
    lock.lock();
  }
  lock.unlock();

  shared_ptr<DeviceKernel> kernel = program->GetKernel("libdnn_scale");
  vector<size_t> work_size(1, n);
  vector<size_t> group;
  vector<size_t> local;
  this->dev_ptr_->get_threads(&work_size, &group, &local, kernel.get(), true);
  kernel->add_arg(&n);
  kernel->add_arg(&alpha);
  kernel->add_arg(&x);
  kernel->add_arg(&y);
  kernel->Execute(group, local);
}
Пример #4
0
void LibDNNBlas<MItype, MOtype>::axpby(const uint_tp n, const MItype alpha,
           vptr<const MItype> x, const MOtype beta, vptr<MOtype> y,
           const QuantizerValues* const alpha_quant,
           const QuantizerValues* const x_quant,
           const QuantizerValues* const beta_quant,
           const QuantizerValues* const y_quant) {

  typedef typename std::conditional<float_is_same<MItype>::value, MItype,
          typename std::conditional<sizeof(MItype) == 1, int16_t,
          typename std::conditional<sizeof(MItype) == 2, int32_t,
                                    int64_t>::type>::type>::type Difftype;
  typedef typename std::conditional<float_is_same<MItype>::value, MItype,
          typename std::conditional<sizeof(MItype) == 1, int32_t,
                                    int64_t>::type>::type Acctype;
  string identifier = axpby_string_identifier();

  int_tp id = get_id(identifier);
  if (id < 0) {
    id = get_id_or_new(identifier);
  }
  shared_ptr<LibDNNTuner> tuner = program_tuners_[id];
  shared_ptr<DeviceProgram> program = programs_[id];
  boost::shared_lock<boost::shared_mutex> lock(program_mutex_);
  if (!program_ready_[id]) {
    lock.unlock();
    // Compiling new kernel has to lock the program lock exclusively
    boost::unique_lock<boost::shared_mutex> ulock(program_mutex_);
    if (!program_ready_[id]) {
      stringstream ss;
      ss << generate_axpby_source(program, tuner);
      program->set_source(ss.str());
      program->Compile(true, true);
      program_ready_[id] = true;
    }
    ulock.unlock();
    lock.lock();
  }
  lock.unlock();

  shared_ptr<DeviceKernel> kernel = program->GetKernel("libdnn_axpby");
  vector<size_t> work_size(1, n);
  vector<size_t> group;
  vector<size_t> local;
  this->dev_ptr_->get_threads(&work_size, &group, &local, kernel.get(), true);

  // Quantization parameters
  int8_t shift_bits =
      (this->dev_ptr_->template preferred_vector_width<int64_t>() > 0 ? 32 : 16)
      / sizeof(MItype) - 1;

  MItype x_off;
  MOtype y_off;
  Acctype y_min;
  Acctype y_max;
  MItype alpha_off;
  int32_t alpha_mult;
  int8_t alpha_shift;
  MOtype beta_off;
  int32_t beta_mult;
  int8_t beta_shift;

  if (is_integer_type<MItype>() || is_integer_type<MOtype>()) {
    x_off = x_quant->get_zero<MItype>();
    y_off = y_quant->get_zero<MOtype>();
    y_min = y_quant->get_min<Acctype>();
    y_max = y_quant->get_max<Acctype>();

    QuantizerValues qv_alpha;
    if (!alpha_quant) {
      qv_alpha.max = 1.0;
      qv_alpha.min = 0.0;
      qv_alpha.one = 1.0;
      qv_alpha.zero = 0.0;
      qv_alpha.scale = 1.0;
    }

    QuantizerValues qv_beta;
    if (!beta_quant) {
      qv_beta.max = 1.0;
      qv_beta.min = 0.0;
      qv_beta.one = 1.0;
      qv_beta.zero = 0.0;
      qv_beta.scale = 1.0;
    }

    alpha_off = alpha_quant ? alpha_quant->get_zero<MItype>()
                            : qv_alpha.get_zero<MItype>();
    beta_off = beta_quant ? beta_quant->get_zero<MOtype>()
                          : qv_beta.get_zero<MOtype>();

    QuantizerBase::template MultiplicativeQuantVals<int32_t>(
        x_quant, alpha_quant ? alpha_quant : &qv_alpha,
        y_quant, &alpha_mult, &alpha_shift, shift_bits);
    QuantizerBase::template MultiplicativeQuantVals<int32_t>(
        y_quant, beta_quant ? beta_quant : &qv_beta,
        y_quant, &beta_mult, &beta_shift, shift_bits);
  }

  if (is_integer_type<MItype>() || is_integer_type<MOtype>()) {
    kernel->add_arg(&shift_bits);
  }
  kernel->add_arg(&n);
  kernel->add_arg(&alpha);
  if (is_integer_type<MItype>()) {
    kernel->add_arg(&alpha_off);
    kernel->add_arg(&alpha_mult);
    kernel->add_arg(&alpha_shift);
  }
  kernel->add_arg(&x);
  if (is_integer_type<MItype>()) {
    kernel->add_arg(&x_off);
  }
  kernel->add_arg(&beta);
  if (is_integer_type<MOtype>()) {
    kernel->add_arg(&beta_off);
    kernel->add_arg(&beta_mult);
    kernel->add_arg(&beta_shift);
  }
  kernel->add_arg(&y);
  if (is_integer_type<MOtype>()) {
    kernel->add_arg(&y_off);
    kernel->add_arg(&y_min);
    kernel->add_arg(&y_max);
  }
  kernel->Execute(group, local);
}