Exemplo n.º 1
0
unit_const_ptr entity_location::get_unit() const
{
	if(!resources::gameboard) {
		return nullptr;
	}
	if(id_ == 0) {
		auto un_it = resources::gameboard->units().find(*this);
		if(un_it.valid()) {
			return un_it.get_shared_ptr();
		}
		return nullptr;
	}
	return resources::gameboard->units().find(id_).get_shared_ptr();
}
Exemplo n.º 2
0
unit_const_ptr entity_location::get_unit() const
{
	if(resources::units == nullptr) {
		return nullptr;
	}
	if(id_ == 0) {
		auto un_it = resources::units->find(*this);
		if(un_it.valid()) {
			return un_it.get_shared_ptr();
		}
		return nullptr;
	}
	return resources::units->find(id_).get_shared_ptr();
}
Exemplo n.º 3
0
Dtype* MKLMemoryDescriptor<Dtype, is_diff>::get_converted_prv(
  Blob<Dtype>* blob, bool set_prv_ptr,
  MKLMemoryDescriptor<Dtype, is_diff>* converted_in_fwd) {
  if (this->convert_to_int) {
    int status;
    void *convert_resources[dnnResourceNumber];
    const Dtype* prv_ptr = is_diff ?  blob->prv_diff() : blob->prv_data();
    if (prv_ptr == NULL) {
      if (converted_in_fwd) {
        // hack for reusing previously done conversion
        // if(dnnLayoutCompare(converted_in_fwd->layout_int , this->layout_int))
        if (1) {
          DLOG(INFO) << "reusing fwd               "
                  << converted_in_fwd->name << " == " << this->name;
          return converted_in_fwd->internal_ptr;
        } else {
          DLOG(INFO) << "layout doesn't match      "
                  << converted_in_fwd->name << " != " << this->name;
        }
      }

      DLOG(INFO) << "convert      => priv                                => "
                 << this->name;

      convert_resources[dnnResourceFrom] =
              is_diff ?
                reinterpret_cast<void *>(const_cast<Dtype*>(blob->cpu_diff()))
              : reinterpret_cast<void *>(const_cast<Dtype*>(blob->cpu_data()));
      convert_resources[dnnResourceTo] =
              reinterpret_cast<void *>(this->internal_ptr);

      status = dnnExecute<Dtype>(this->convert_to_int, convert_resources);
      CHECK_EQ(status, 0) << "Conversion failed with status " << status;

      if (set_prv_ptr) {
        if (is_diff)
          blob->set_prv_diff(this->internal_ptr, get_shared_ptr(), true);
        else
          blob->set_prv_data(this->internal_ptr, get_shared_ptr(), true);
      }
      return this->internal_ptr;
    } else {
      // This section helps if padding needs to be added (or removed...)
      // TODO: consider removing when no longer needed.
      shared_ptr<PrvMemDescr> prv_mem_descriptor =
          is_diff ? (blob->get_prv_descriptor_diff()) :
            (blob->get_prv_descriptor_data());

      CHECK_EQ(prv_mem_descriptor->get_descr_type(),
              PrvMemDescr::PRV_DESCR_MKL2017);

      shared_ptr<MKLMemoryDescriptor<Dtype, is_diff> > current_descr =
        boost::static_pointer_cast<MKLMemoryDescriptor<Dtype, is_diff> >
              (prv_mem_descriptor);

      if (!dnnLayoutCompare<Dtype>(current_descr->layout_int,
              this->layout_int)) {
        if (converted_in_fwd) {
          // hack for reusing previously done conversion
          // if(dnnLayoutCompare(converted_in_fwd->layout_int,this->layout_int))
          if (1) {
            DLOG(INFO) << "reusing fwd               "
                    << converted_in_fwd->name << " == " << this->name;
            return converted_in_fwd->internal_ptr;
          } else {
            DLOG(INFO) << "layout doesn't match      "
                    << converted_in_fwd->name << " != " << this->name;
          }
        }
        DLOG(INFO) << "convert priv => priv      "
                << current_descr->name << " => " << this->name;

        dnnPrimitive_t convert_padding;
        status = dnnConversionCreate<Dtype>(&convert_padding,
                current_descr->layout_int , this->layout_int);
        // CHECK_EQ(status, 0)
        // << "Failed creation convert_padding with status " << status << "\n";
        if (status != 0) {
          // TODO: Very weird that we end up here for conv1. No idea why....
          DLOG(INFO) << "!!!! Failed creation convert_padding with status "
                  << status << "\n";

          convert_resources[dnnResourceFrom] = is_diff ?
            reinterpret_cast<void *>(const_cast<Dtype*>(blob->cpu_diff())) :
            reinterpret_cast<void *>(const_cast<Dtype*>(blob->cpu_data()));
          convert_resources[dnnResourceTo] =
            reinterpret_cast<void*>(this->internal_ptr);

          status = dnnExecute<Dtype>(this->convert_to_int, convert_resources);
          CHECK_EQ(status, 0) << "Conversion failed with status " << status;

        } else {
          convert_resources[dnnResourceFrom] = is_diff ?
            reinterpret_cast<void *>(const_cast<Dtype *>(blob->prv_diff())) :
            reinterpret_cast<void *>(const_cast<Dtype *>(blob->prv_data()));
          convert_resources[dnnResourceTo] =
                  reinterpret_cast<void *>(this->internal_ptr);
          status = dnnExecute<Dtype>(convert_padding, convert_resources);
          CHECK_EQ(status, 0) << "Conversion failed with status " << status;
          dnnDelete<Dtype>(convert_padding);
        }

        if (set_prv_ptr) {
          if (is_diff)
            blob->set_prv_diff(this->internal_ptr, get_shared_ptr(), true);
          else
            blob->set_prv_data(this->internal_ptr, get_shared_ptr(), true);
        }
        return this->internal_ptr;
      } else if (current_descr.get() != this) {
        DLOG(INFO) << "layout OK                 "
                << current_descr->name << " == " << this->name;
      }
    }

    return const_cast<Dtype *>(prv_ptr);
  }

  return (is_diff ? const_cast<Dtype *>(blob->cpu_diff()) :
                    const_cast<Dtype *>(blob->cpu_data()));
}