void gpuNUFFT::GpuNUFFTOperator::initDeviceMemory(int n_coils) { if (gpuMemAllocated) return; gi_host = initAndCopyGpuNUFFTInfo();// int data_count = (int)this->kSpaceTraj.count(); IndType imdata_count = this->imgDims.count(); int sector_count = (int)this->gridSectorDims.count(); if (DEBUG) printf("allocate and copy data indices of size %d...\n",dataIndices.count()); allocateAndCopyToDeviceMem<IndType>(&data_indices_d,dataIndices.data,dataIndices.count()); if (DEBUG) printf("allocate and copy data of size %d...\n",data_count); allocateDeviceMem<DType2>(&data_sorted_d,data_count); if (DEBUG) printf("allocate and copy gdata of size %d...\n",gi_host->grid_width_dim); allocateDeviceMem<CufftType>(&gdata_d,gi_host->grid_width_dim); if (DEBUG) printf("allocate and copy coords of size %d...\n",getImageDimensionCount()*data_count); allocateAndCopyToDeviceMem<DType>(&crds_d,this->kSpaceTraj.data,getImageDimensionCount()*data_count); if (DEBUG) printf("allocate and copy kernel in const memory of size %d...\n",this->kernel.count()); initLookupTable(); //allocateAndCopyToDeviceMem<DType>(&kernel_d,kernel,kernel_count); if (DEBUG) printf("allocate and copy sectors of size %d...\n",sector_count+1); allocateAndCopyToDeviceMem<IndType>(§ors_d,this->sectorDataCount.data,sector_count+1); if (DEBUG) printf("allocate and copy sector_centers of size %d...\n",getImageDimensionCount()*sector_count); allocateAndCopyToDeviceMem<IndType>(§or_centers_d,(IndType*)this->getSectorCentersData(),getImageDimensionCount()*sector_count); if (this->applyDensComp()) { if (DEBUG) printf("allocate and copy density compensation of size %d...\n",data_count); allocateAndCopyToDeviceMem<DType>(&density_comp_d,this->dens.data,data_count); } if (this->applySensData()) { if (DEBUG) printf("allocate sens data of size %d...\n",imdata_count); allocateDeviceMem<DType2>(&sens_d,imdata_count); } if (n_coils > 1) { if (DEBUG) printf("allocate precompute deapofunction of size %d...\n",imdata_count); allocateDeviceMem<DType>(&deapo_d,imdata_count); precomputeDeapodization(deapo_d,gi_host); } if (DEBUG) printf("sector pad width: %d\n",gi_host->sector_pad_width); //Inverse fft plan and execution if (DEBUG) printf("creating cufft plan with %d,%d,%d dimensions\n",DEFAULT_VALUE(gi_host->gridDims.z),gi_host->gridDims.y,gi_host->gridDims.x); cufftResult res = cufftPlan3d(&fft_plan, (int)DEFAULT_VALUE(gi_host->gridDims.z),(int)gi_host->gridDims.y,(int)gi_host->gridDims.x, CufftTransformType) ; if (res != CUFFT_SUCCESS) fprintf(stderr,"error on CUFFT Plan creation!!! %d\n",res); gpuMemAllocated = true; }
gpuNUFFT::GpuNUFFTInfo* gpuNUFFT::GpuNUFFTOperator::initGpuNUFFTInfo() { gpuNUFFT::GpuNUFFTInfo* gi_host = (gpuNUFFT::GpuNUFFTInfo*)malloc(sizeof(gpuNUFFT::GpuNUFFTInfo)); gi_host->data_count = (int)this->kSpaceTraj.count(); gi_host->sector_count = (int)this->gridSectorDims.count(); gi_host->sector_width = (int)sectorDims.width; gi_host->kernel_width = (int)this->kernelWidth; gi_host->kernel_widthSquared = (int)(this->kernelWidth * this->kernelWidth); gi_host->kernel_count = (int)this->kernel.count(); gi_host->grid_width_dim = (int)this->getGridDims().count(); gi_host->grid_width_offset= (int)(floor(this->getGridDims().width / (DType)2.0)); gi_host->im_width_dim = (int)imgDims.count(); gi_host->im_width_offset.x = (int)(floor(imgDims.width / (DType)2.0)); gi_host->im_width_offset.y = (int)(floor(imgDims.height / (DType)2.0)); gi_host->im_width_offset.z = (int)(floor(imgDims.depth / (DType)2.0)); gi_host->imgDims.x = imgDims.width; gi_host->imgDims.y = imgDims.height; gi_host->imgDims.z = imgDims.depth; gi_host->imgDims_count = imgDims.width*imgDims.height*DEFAULT_VALUE(imgDims.depth);//TODO check why not imgDims.count() gi_host->gridDims.x = this->getGridDims().width; gi_host->gridDims.y = this->getGridDims().height; gi_host->gridDims.z = this->getGridDims().depth; gi_host->gridDims_count = this->getGridDims().width*this->getGridDims().height*DEFAULT_VALUE(this->getGridDims().depth);//s.a. //The largest value of the grid dimensions determines the kernel radius (resolution) in k-space units int max_grid_dim = MAX(MAX(this->getGridDims().width,this->getGridDims().height),this->getGridDims().depth); double kernel_radius = static_cast<double>(this->kernelWidth) / 2.0; double radius = kernel_radius / static_cast<double>(max_grid_dim); DType kernel_width_inv = (DType)1.0 / static_cast<DType>(this->kernelWidth); double radiusSquared = radius * radius; double kernelRadius_invSqr = 1.0 / radiusSquared; DType dist_multiplier = (DType)((this->kernel.count() - 1) * kernelRadius_invSqr); if (DEBUG) printf("radius rel. to grid width %f\n",radius); gpuNUFFT::Dimensions sectorPadDims = sectorDims + 2*(int)(floor(this->kernelWidth / (DType)2.0)); int sector_pad_width = (int)sectorPadDims.width; int sector_dim = (int)sectorPadDims.count(); int sector_offset = (int)(floor(sector_pad_width / (DType)2.0)); gi_host->grid_width_inv.x = (DType)1.0 / static_cast<DType>(this->getGridDims().width); gi_host->grid_width_inv.y = (DType)1.0 / static_cast<DType>(this->getGridDims().height); gi_host->grid_width_inv.z = (DType)1.0 / static_cast<DType>(this->getGridDims().depth); gi_host->kernel_widthInvSquared = kernel_width_inv * kernel_width_inv; gi_host->osr = this->osf; gi_host->kernel_radius = (DType)kernel_radius; gi_host->sector_pad_width = sector_pad_width; gi_host->sector_pad_max = sector_pad_width - 1; gi_host->sector_dim = sector_dim; gi_host->sector_offset = sector_offset; gi_host->aniso_x_scale = ((DType)this->getGridDims().width/(DType)max_grid_dim); gi_host->aniso_y_scale = ((DType)this->getGridDims().height/(DType)max_grid_dim); gi_host->aniso_z_scale = ((DType)this->getGridDims().depth/(DType)max_grid_dim); gi_host->radiusSquared = (DType)radiusSquared; gi_host->radiusSquared_inv = (DType)kernelRadius_invSqr; gi_host->dist_multiplier = dist_multiplier; gi_host->is2Dprocessing = this->is2DProcessing(); return gi_host; }
/** \brief Compute total count of array length * */ IndType count() { return DEFAULT_VALUE(length) * DEFAULT_VALUE(width) * DEFAULT_VALUE(height) * DEFAULT_VALUE(depth) * DEFAULT_VALUE(channels) * DEFAULT_VALUE(frames); }