コード例 #1
0
void* SyncedMemory::mutable_cpu_data() {
	if( size_==0 || !own_cpu_data_ )
	{
		to_cpu();
	}
		head_ = HEAD_AT_CPU;
  		return cpu_ptr_;
}
コード例 #2
0
ファイル: asr.c プロジェクト: Distrotech/dmraid
/*
 * Attempt to interpret ASR metadata from a block device.  This function
 * returns either NULL (not an ASR) or a pointer to a descriptor struct.
 * Note that the struct should be fully converted to the correct endianness
 * by the time this function returns.
 *
 * WARNING: If you take disks out of an ASR HostRAID array and plug them in
 * to a normal SCSI controller, the array will still show up!  Even if you
 * scribble over the disks!  I assume that the a320raid binary driver only
 * does its HostRAID magic if your controller is in RAID mode... but dmraid
 * lacks this sort of visibility as to where its block devices come from.
 * This is EXTREMELY DANGEROUS if you aren't careful!
 */
static void *
read_metadata_areas(struct lib_context *lc, struct dev_info *di,
		    size_t * sz, uint64_t * offset, union read_info *info)
{
	size_t size = ASR_DISK_BLOCK_SIZE;
	uint64_t asr_sboffset = ASR_CONFIGOFFSET;
	struct asr *asr;
	struct asr_raid_configline *cl;

	/*
	 * Read the ASR reserved block on each disk.  This is the very
	 * last sector of the disk, and we're really only interested in
	 * the two magic numbers, the version, and the pointer to the
	 * RAID table.  Everything else appears to be unused in v8.
	 */
	if (!(asr = alloc_private(lc, handler, sizeof(*asr))))
		goto bad0;

	if (!(asr->rt = alloc_private(lc, handler, sizeof(*asr->rt))))
		goto bad1;

	if (!read_file(lc, handler, di->path, &asr->rb, size, asr_sboffset))
		goto bad2;

	/*
	 * Convert metadata and read in 
	 */
	to_cpu(asr, ASR_BLOCK);

	/* Check Signature and read optional extended metadata. */
	if (!is_asr(lc, di, asr) || !read_extended(lc, di, asr))
		goto bad2;

	/*
	 * Now that we made sure that we have all the metadata, we exit.
	 */
	cl = this_disk(asr);
	if (cl->raidstate == LSU_COMPONENT_STATE_FAILED)
		goto bad2;

	goto out;

      bad2:
	dbg_free(asr->rt);
      bad1:
	asr->rt = NULL;
	dbg_free(asr);
      bad0:
	asr = NULL;

      out:
	return asr;
}
コード例 #3
0
void SyncedMemory::release(){
  // if (cpu_ptr_ && own_cpu_data_) {
  //  CaffeFreeHost(cpu_ptr_);
 // }
  to_cpu();
  if (gpu_ptr_) {
    CUDA_CHECK(cudaFree(gpu_ptr_));
  }
  head_ =HEAD_AT_CPU;
  gpu_ptr_=NULL;
  
}
コード例 #4
0
void* SyncedMemory::cpu_data() {
	if(size_==0)
	{
		to_cpu();
	}
	else
	{
		if(head_==UNINITIALIZED)
		caffe_memset(size_, 0, cpu_ptr_);
	}
  	
  return (void*)cpu_ptr_;
}
コード例 #5
0
void* SyncedMemory::mutable_cpu_data() {
  // LOG(INFO)<<"calling mutable_cpu_data";
  // switch (head_) {
  // case UNINITIALIZED:
	// LOG(INFO)<<"MEM not initilaized";
	// break;
  // case HEAD_AT_CPU:
     // LOG(INFO)<<"MEM is in CPU";
	// break;
  // case HEAD_AT_GPU:
    // LOG(INFO)<<"MEM is in GPU";
	// break;
	// }
  to_cpu();
  head_ = HEAD_AT_CPU;
  return cpu_ptr_;
}
コード例 #6
0
ファイル: asr.c プロジェクト: Distrotech/dmraid
/* Read extended metadata areas */
static int
read_extended(struct lib_context *lc, struct dev_info *di, struct asr *asr)
{
	unsigned remaining, i, chk;
	struct asr_raidtable *rt = asr->rt;

	log_notice(lc, "%s: reading extended data on %s", handler, di->path);

	/* Read the RAID table. */
	if (!read_file(lc, handler, di->path, rt, ASR_DISK_BLOCK_SIZE,
		       (uint64_t) asr->rb.raidtbl * ASR_DISK_BLOCK_SIZE))
		LOG_ERR(lc, 0, "%s: Could not read metadata off %s",
			handler, di->path);

	/* Convert it */
	to_cpu(asr, ASR_TABLE);

	/* Is this ok? */
	if (rt->ridcode != RVALID2)
		LOG_ERR(lc, 0, "%s: Invalid magic number in RAID table; "
			"saw 0x%X, expected 0x%X on %s",
			handler, rt->ridcode, RVALID2, di->path);

	/* Have we a valid element count? */
	if (rt->elmcnt >= rt->maxelm || rt->elmcnt == 0)
		LOG_ERR(lc, 0, "%s: Invalid RAID config table count on %s",
			handler, di->path);

	/* Is each element the right size? */
	if (rt->elmsize != sizeof(*rt->ent))
		LOG_ERR(lc, 0, "%s: Wrong RAID config line size on %s",
			handler, di->path);

	/* Figure out how much else we need to read. */
	if (rt->elmcnt > ASR_TBLELMCNT) {
		remaining = rt->elmsize * (rt->elmcnt - 7);
		if (!read_file(lc, handler, di->path, rt->ent + 7,
			       remaining, (uint64_t) (asr->rb.raidtbl + 1) *
			       ASR_DISK_BLOCK_SIZE))
			return 0;

		to_cpu(asr, ASR_EXTTABLE);
	}

	/* Checksum only valid for raid table version 1. */
	if (rt->rversion < 2) {
		if ((chk = compute_checksum(asr)) != rt->rchksum)
			log_err(lc, "%s: Invalid RAID config table checksum "
				"(0x%X vs. 0x%X) on %s",
				handler, chk, rt->rchksum, di->path);
	}

	/* Process the name of each line of the config line. */
	for (i = 0; i < rt->elmcnt; i++) {
		/* 
		 * Weird quirks of the name field of the config line:
		 *
		 * - SATA HostRAID w/ ICH5 on IBM x226: The name field is null
		 *   in the drive config lines.  The zeroeth item does have a
		 *   name, however.
		 * - Spares on SCSI HostRAID on IBM x226: The name field for
		 *   all config lines is null.
		 * 
		 * So, we'll assume that we can copy the name from the zeroeth
		 * element in the array.  The twisted logic doesn't seem to
		 * have a problem with either of the above cases, though
		 * attaching spares is going to be a tad tricky (primarily
		 * because there doesn't seem to be a way to attach a spare to
		 * a particular array; presumably the binary driver knows how
		 * or just grabs a disk out of the spare pool.
		 *
		 * (Yes, the binary driver _does_ just grab a disk from the
		 * global spare pool.  We must teach dm about this...?)
		 *
		 * This is nuts.
		 */
		if (!*rt->ent[i].name)
			strncpy((char *) rt->ent[i].name,
				(char *) rt->ent->name, ASR_NAMELEN);

		/* Now truncate trailing whitespace in the name. */
		handle_white_space(rt->ent[i].name, TRUNCATE);
	}

	return 1;
}
コード例 #7
0
ファイル: syncedmem.cpp プロジェクト: AlOa/caffe
void* SyncedMemory::mutable_cpu_data() {
  to_cpu();
  head_ = HEAD_AT_CPU;
  return cpu_ptr_;
}
コード例 #8
0
ファイル: syncedmem.cpp プロジェクト: AlOa/caffe
const void* SyncedMemory::cpu_data() {
  to_cpu();
  return (const void*)cpu_ptr_;
}