Пример #1
0
void petabricks::MatrixStorageInfo::setStorage(const MatrixStoragePtr& s, const ElementT* base){
  if(s){
    _storage=s;
    JASSERT(base >= s->data());
    JASSERT(base < s->data()+s->count());
    _baseOffset=base-s->data();
  }else{
    _storage=NULL;
    _baseOffset=0;
  }
  _hash=HashT();
}
Пример #2
0
void RegionDataRemote::copyFromScratchMatrixStorage(CopyFromMatrixStorageMessage* origMsg, size_t len, MatrixStoragePtr scratchStorage, RegionMatrixMetadata* scratchMetadata, const IndexT* scratchStorageSize) {
  if (isDataSplit()) {
    this->copyRegionDataSplit();
    _localRegionDataSplit->copyFromScratchMatrixStorage(origMsg, len, scratchStorage, scratchMetadata, scratchStorageSize);
    return;
  }

  RegionMatrixMetadata* origMetadata = &(origMsg->srcMetadata);
  int d = origMetadata->dimensions;
  IndexT* size = origMetadata->size();

  size_t storageCount = 1;
  for (int i = 0; i < d; ++i) {
    storageCount *= size[i];
  }

  // Copy storage.
  if (storageCount == scratchStorage->count()) {
    // Special case: copy the entire storage
    memcpy(origMsg->storage(), scratchStorage->data(), sizeof(ElementT) * storageCount);

  } else {
    int n = 0;
    IndexT coord[d];
    memset(coord, 0, sizeof coord);
    IndexT multipliers[d];
    sizeToMultipliers(d, scratchStorageSize, multipliers);
    do {
      IndexT scratchIndex = toRegionDataIndex(d, coord, scratchMetadata->numSliceDimensions, scratchMetadata->splitOffset, scratchMetadata->sliceDimensions(), scratchMetadata->slicePositions(), multipliers);
      origMsg->storage()[n] = scratchStorage->data()[scratchIndex];
      ++n;
    } while(incCoord(d, size, coord) >= 0);
  }

#ifdef PRINT_COPY_COUNT
  JTRACE("copy from scratch")(storageCount);
#endif

  size_t msgLen =  RegionMatrixMetadata::len(origMetadata->dimensions, origMetadata->numSliceDimensions) + (sizeof(ElementT) * storageCount);
  JASSERT(msgLen <= len);

  void* data;
  size_t replyLen;
  int type;
  this->fetchData(origMsg, MessageTypes::FROMSCRATCHSTORAGE, msgLen, &data, &replyLen, &type);
  free(data);
}
Пример #3
0
RegionDataIPtr RegionDataRemote::copyToScratchMatrixStorage(CopyToMatrixStorageMessage* origMsg, size_t len, MatrixStoragePtr scratchStorage, RegionMatrixMetadata* scratchMetadata, const IndexT* scratchStorageSize, RegionDataI** newScratchRegionData) {
  if (isDataSplit()) {
    RegionDataI* rv = NULL;
    if (this->copyRegionDataSplit()) {
      rv = _localRegionDataSplit.asPtr();
    }
    _localRegionDataSplit->copyToScratchMatrixStorage(origMsg, len, scratchStorage, scratchMetadata, scratchStorageSize, newScratchRegionData);
    return rv;
  }

  void* data;
  size_t replyLen;
  int type;
  this->fetchData(origMsg, MessageTypes::TOSCRATCHSTORAGE, len, &data, &replyLen, &type);
  BaseMessageHeader* base = (BaseMessageHeader*)data;
  len = len - base->contentOffset;

  JASSERT(type == MessageTypes::TOSCRATCHSTORAGE);
  CopyToMatrixStorageReplyMessage* reply = (CopyToMatrixStorageReplyMessage*) base->content();

#ifdef PRINT_COPY_COUNT
  JTRACE("copy to scratch")(reply->count);
#endif

  if (reply->count == scratchStorage->count()) {
    memcpy(scratchStorage->data(), reply->storage, sizeof(ElementT) * reply->count);

  } else {
    RegionMatrixMetadata* origMetadata = &(origMsg->srcMetadata);
    int d = origMetadata->dimensions;
    IndexT* size = origMetadata->size();

    int n = 0;
    IndexT coord[d];
    memset(coord, 0, sizeof coord);
    IndexT multipliers[d];
    sizeToMultipliers(d, scratchStorageSize, multipliers);
    do {
      IndexT scratchIndex = toRegionDataIndex(d, coord, scratchMetadata->numSliceDimensions, scratchMetadata->splitOffset, scratchMetadata->sliceDimensions(), scratchMetadata->slicePositions(), multipliers);
      scratchStorage->data()[scratchIndex] = reply->storage[n];
      ++n;
    } while(incCoord(d, size, coord) >= 0);
  }

  free(data);
  return NULL;
}