Ejemplo n.º 1
0
volume* Volume::createFloatVolume(volume* iVolume)
{
    INFO("Creating FLAT FLOAT32 volume : "
              + STRG( "[" ) + ITS( iVolume->sizeX ) + STRG( "]" ) + " x "
              + STRG( "[" ) + ITS( iVolume->sizeY ) + STRG( "]" ) + " x "
              + STRG( "[" ) + ITS( iVolume->sizeZ ) + STRG( "]" ));

    /* @ Allocating float flat array */
    float* flatVol_float = (float*) malloc
            (sizeof(float*) * iVolume->sizeX * iVolume->sizeY * iVolume->sizeZ);

    /* @ Type conversion */
    for (int i = 0; i < iVolume->sizeX * iVolume->sizeY * iVolume->sizeZ; i++)
        flatVol_float[i] = (float) (unsigned char) iVolume->ptrVol_char[i];

    /* @ linking the float array to the original volume structure */
    iVolume->ptrVol_float = flatVol_float;

    INFO("Freeing the BYTE volume");

    /* @ freeing the BYTE volume */
    free((iVolume->ptrVol_char));

    INFO("Creating FLAT FLOAT32 volume DONE");

    return iVolume;
}
Ejemplo n.º 2
0
void Volume::extractSubVolume(char*** originalCubeVol,
                              char*** finalCubeVol,
                              const subVolDim* iSubVolDim)
{
    /* @ Calculating the sub volume dimensions */
    const int finalSize_X = iSubVolDim->max_X - iSubVolDim->min_X;
    const int finalSize_Y = iSubVolDim->max_Y - iSubVolDim->min_Y;
    const int finalSize_Z = iSubVolDim->max_Z - iSubVolDim->min_Z;

    INFO("Extracting SUB-VOLUME with dimensions : "
         + STRG( "[" ) + ITS( finalSize_X ) + STRG( "]" ) + " x "
         + STRG( "[" ) + ITS( finalSize_Y ) + STRG( "]" ) + " x "
         + STRG( "[" ) + ITS( finalSize_Y ) + STRG( "]" ));

    for (int i = 0; i < finalSize_X; i++)
    {
        for (int j = 0; j < finalSize_Y; j++)
        {
            for (int k = 0; k < finalSize_Z; k++)
            {
                finalCubeVol[i][j][k] = originalCubeVol
                        [(iSubVolDim->min_X) + i]
                        [(iSubVolDim->min_Y) + j]
                        [(iSubVolDim->min_Z) + k];
            }
        }
    }

    INFO("Extracting SUB-VOLUME DONE");
}
Ejemplo n.º 3
0
void FlatVolume<T>::AllocateVolume()
{
    INFO("Allocating the volume : " +
         ITS(NXYZ) + CATS(" voxels") + CATS(" - ") +
         ITS(volumeSize) + CATS(" Bytes"));

    // Volume allocation
    this->ptrVolumeData = (T*) malloc (volumeSize);

    INFO("The FLAT volume has been successfully allocated in 1D array");
}
Ejemplo n.º 4
0
void FlatVolume<T>::FreeVolume()
{
    INFO("Freeing a volume data block of size: " +
         CATS("[") + ITS(NX) + CATS("] X [") +
         ITS(NY) + CATS("] X [") + ITS(NZ) + CATS("]") +
         CATS(" - ") + ITS(volumeSize) + " Bytes");

    // Release volume data memory block
    free(this->ptrVolumeData);

    INFO("Freeing volume data has been done successfully");
}
Ejemplo n.º 5
0
void ex_FFTShift::FFTShift_2D_CUDA(int size_X, int size_Y)
{
	LOG();


	INFO("2D FFT Shift - CUDA" + ITS(size_X) + "x" + ITS(size_Y));

	// Host allocation
	arr_2D_flat_float = MEM_ALLOC_1D_FLOAT(size_X * size_Y);

	// Filling array
	Array::fillArray_2D_flat_float(arr_2D_flat_float, size_X, size_Y, 1);

	// Printing input
	int ctr = 0;
	for (int i = 0; i < size_X; i++)
		for (int j = 0; j < size_Y; j++)
		{
			if (ctr == 0 || ctr == size_X * size_Y - 1 )
				printf("Input \t %f \n", arr_2D_flat_float[ctr]);

			ctr++;
		}


	// Device allocation
	int devMem = size_X * size_Y * sizeof(float);
	cudaMalloc((void**)(&dev_arr_2D_flat_float), devMem);

	// Uploading array
	cuUtils::upload_2D_float(arr_2D_flat_float, dev_arr_2D_flat_float, size_X, size_Y);

	// CUDA Gridding
	dim3 cuBlock(8, 8, 1);
	dim3 cuGrid(size_X / cuBlock.x, size_Y / cuBlock.y, 1);

	// FFT shift
	//cuFFTShift_2D( cuBlock, cuGrid, dev_arr_2D_flat_float, dev_arr_2D_flat_float, size_X);

	// Downloading array
	cuUtils::download_2D_float(arr_2D_flat_float, dev_arr_2D_flat_float, size_X, size_Y);

	// Printing output
	ctr = 0;
	for (int i = 0; i < size_X; i++)
		for (int j = 0; j < size_Y; j++)
		{
			if (ctr == 0 || ctr == size_X * size_Y - 1 )
				printf("output \t %f \n", arr_2D_flat_float[ctr]);

			ctr++;
		}
}
Ejemplo n.º 6
0
// Constructor
template <class T> Image<T>::Image
(const int NX, const int NY) : NX(NX), NY(NY)
{
    INFO("Creating a 2D Image object of size : " +
         CATS("[") + ITS(NX) + CATS("] X [") + ITS(NY) + CATS("]"));

    // Total number of pixels in the image
    this->NXY = NX * NY;

    // Image size in Bytes
    ImageSize = sizeof(T) * this->NXY;

    // Allocating the Image data memory block
    Image::AllocateImage();
}
Ejemplo n.º 7
0
// Constructor
template <class T> FlatVolume<T>::FlatVolume
(const int NX, const int NY, const int NZ) : NX(NX), NY(NY), NZ(NZ)
{
    INFO("Creating a FLAT volume object of size : " +
         CATS("[") + ITS(NX) + CATS("] X [") +
         ITS(NY) + CATS("] X [") + ITS(NZ) + CATS("]"));

    // Total number of voxels in the volume
    NXYZ = NX * NY * NZ;

    // Volume size in Bytes
    volumeSize = sizeof(T) * NXYZ;

    FlatVolume::AllocateVolume();
}
Ejemplo n.º 8
0
void Image<T>::AllocateImage()
{
    INFO("Allocating a 2D Image : " +
         ITS(this->NXY) + CATS(" pixels") + CATS(" - ") +
         ITS(this->ImageSize) + CATS(" Bytes"));

    // 2D Image allocation
    this->ptrImageData = (T**) malloc (sizeof(T*) * this->NX);

    for(int j = 0; j < this->NX; j++)
    {
        this->ptrImageData[j] = (T*) malloc (sizeof(T) * this->NY);
    }

    INFO("The Image has been successfully allocated 3D array");
}
Ejemplo n.º 9
0
void ReadVolume(char *prefix)
{
    char imgFile[100];
    ifstream inputFileStream;

    // Reading the header file
    ReadHeader(prefix, iWidth, iHeight, iDepth);
    INFO("Volume size: [" + ITS(iWidth) + "X" +
         ITS(iHeight) + "x" + ITS(iDepth) + "]");

    // Adding the ".img" prefix to the dataset path
    sprintf(imgFile, "%s.img", prefix);
    INFO("Reading the volume file " + CATS(imgFile));

    // Total number of voxels
    numVoxels = iWidth * iHeight * iDepth;
    INFO("Number of voxels : " + ITS(numVoxels));

    // Allocating the luminance image
    luminanceImage = new GLubyte [numVoxels];

    // Allocating the RGBA image
    rgbaImage = new GLubyte [numVoxels * 4];

    // Reading the volume image (luminance values)
    inputFileStream.open(imgFile, ios::in);
    if (inputFileStream.fail())
    {
        INFO("Could not open " + CATS(imgFile));
        EXIT(0);
    }

    // Read the image byte by byte
    inputFileStream.read((char *)luminanceImage, numVoxels);

    // Closing the input volume stream
    inputFileStream.close();

    // Update the volume
    UpdateVolume();

    INFO("The volume has been read successfull and the RGBA one is DONE");
}
Ejemplo n.º 10
0
void Image<T>::FreeImage()
{
    INFO("Freeing a 3D Image data block of size: " +
         CATS("[") + ITS(this->NX) + CATS("] X [") +
         ITS(this->NY) + CATS("]") + CATS(" - ") +
         ITS(this->ImageSize) + " Bytes");

    for(int j = 0; j < this->NY; j++)
    {
        // Release Y
        free(this->ptrImageData[j]);
    }

    // Release X
    free(this->ptrImageData);

    // Nulling the dangling pointer
    this->ptrImageData = NULL;

    INFO("Freeing 2D Image data has been done successfully");
}
Ejemplo n.º 11
0
void Volume::packCubeVolume(char*** cubeVolume, volume* iVolume)
{
    INFO("Packing FLAT volume in CUBE array : "
         + STRG( "[" ) + ITS( iVolume->sizeX ) + STRG( "]" ) + " x "
         + STRG( "[" ) + ITS( iVolume->sizeY ) + STRG( "]" ) + " x "
         + STRG( "[" ) + ITS( iVolume->sizeZ ) + STRG( "]" ));

    int voxel = 0;
    for (int i = 0; i < iVolume->sizeX; i++)
    {
        for (int j = 0; j < iVolume->sizeY; j++)
        {
            for (int k = 0; k < iVolume->sizeZ; k++)
            {
                cubeVolume[i][j][k] = iVolume->ptrVol_char[voxel];
                voxel++;
            }
        }
    }

    INFO("Packing FLAT volume in CUBE array DONE");
}
Ejemplo n.º 12
0
int main(int argc, char **argv) {
	long start = clock();

	FILE *out;
	Results *pres;
	char in_file_name[80];
	char out_file_name[80];
	char summary_file_name[80];
	int i, j;
	int b1, b2;
	int count;
	int sind;
	long time_limit;
	long iterations_coef;
	double seeds[11] = { 0, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000,
			9000, 10000 };
	char out_file[80];
	char numbs[31][2] = { { '0' }, { '1' }, { '2' }, { '3' }, { '4' }, { '5' },
			{ '6' }, { '7' }, { '8' }, { '9' }, { '1', '0' } };
	double av_value = 0., av_time = 0.;

	if (argc <= 3) {
		printf("  specify data and output files");
		exit(1);
	}
	strcpy(in_file_name, argv[1]);
	strcpy(out_file_name, argv[2]);
	strcpy(summary_file_name, argv[3]);
	pres = (Results *) calloc(1, sizeof(Results));
	if ((out = fopen(summary_file_name, "w")) == NULL) {
		printf("  fopen failed for output  %s", summary_file_name);
		exit(1);
	}
	sind = strlen(argv[2]) - 1;

	iterations_coef = 1000;
	time_limit = (long) 1;
	b1 = 30;
	b2 = 30;
	count = 10;
	int pos_ponto;
	for (i = 1; i <= count; i++) {

		for (j = 0; j < 80; j++) {

			if (out_file_name[j]=='.') {
				pos_ponto = j;
				break;
			}
			//out_file[j] = out_file_name[j];

		}
		strncpy(out_file, out_file_name, pos_ponto);
		out_file[pos_ponto] = '0';
		out_file[pos_ponto+1] = i + '0';
		out_file[pos_ponto+2] =  '.';
		//strncpy(out_file, &out_file_name[pos_ponto], 3);
		if (i==1) strcat(out_file, "txt");
		//out_file[]=0;
/*		if (i < 10) {
			for (j = 79; j > sind + 1; j--)
				out_file[j] = out_file[j - 1];
			out_file[sind + 1] = numbs[i][0];
		} else {
			for (j = 79; j > sind + 2; j--)
				out_file[j] = out_file[j - 2];
			out_file[sind + 1] = numbs[i][0];
			out_file[sind + 2] = numbs[i][1];
		}*/
		ITS(in_file_name, out_file, b1, b2, seeds[i], iterations_coef,
				time_limit, pres);
		fprintf(out, "    %11.3lf       %8ld\n", pres->value,
				pres->time_to_opt);
		av_value += pres->value;
		av_time += pres->time_to_opt;
	}
	av_value /= count;
	av_time /= count;
	fprintf(out, "     %11.3lf    %11.3lf\n", av_value, av_time);


	long end = clock();
	long elapsed_time = (long) (end - start) / CLK_TCK;
	fprintf(out, "elapsed time:  %ld\n", elapsed_time);
	fclose(out);
	return 0;
}
Ejemplo n.º 13
0
void iB_FFTShift::FFTShift_2D_Float(int size_X, int size_Y, Sheet* xlSheet, int nLoop)
{
	LOG();

	INFO("2D FFT Shift Float - CPU " + ITS(size_X) + "x" + ITS(size_Y));

	/**********************************************************
	 * Float Case
	 **********************************************************/

	if (xlSheet)
	{
		for (int iLoop = 0; iLoop < nLoop; iLoop++)
		{
			// Headers
			xlSheet->writeStr(1, ((iLoop * 4) + 0), "I-CPU");
			xlSheet->writeStr(1, ((iLoop * 4) + 1), "O-CPU");
			xlSheet->writeStr(1, ((iLoop * 4) + 2), "I-GPU");
			xlSheet->writeStr(1, ((iLoop * 4) + 3), "O-GPU");

			// Allocation: 2D, Flat, Device
			arr_2D_float = MEM_ALLOC_2D_FLOAT(size_X, size_Y);
			arr_2D_flat_float = MEM_ALLOC_1D_FLOAT(size_X * size_Y);
			int devMem = size_X * size_Y * sizeof(float);
			cudaMalloc((void**)(&dev_arr_2D_flat_float), devMem);

			// Filling arrays: 2D, Flat
			Array::fillArray_2D_float(arr_2D_float, size_X, size_Y, 1);
			Array::fillArray_2D_flat_float(arr_2D_flat_float, size_X, size_Y, 1);

			// Printing input
			ctr = 0;
			for (int i = 0; i < size_X; i++)
				for (int j = 0; j < size_Y; j++)
					xlSheet->writeNum((ctr++) + 2, iLoop * 4, arr_2D_float[i][j]);

			// FFT shift operation - CPU
			arr_2D_float = FFT::FFT_Shift_2D_float(arr_2D_float, size_X, size_Y);

			// Printing CPU output
			ctr = 0;
			for (int i = 0; i < size_X; i++)
				for (int j = 0; j < size_Y; j++)
					xlSheet->writeNum((ctr++) + 2, ((iLoop * 4 ) + 1), arr_2D_float[i][j]);

			// Printing GPU input
			ctr = 0;
			for (int i = 0; i < size_X; i++)
				for (int j = 0; j < size_Y; j++)
				{
					xlSheet->writeNum(ctr + 2, ((iLoop * 4 ) + 2), arr_2D_flat_float[ctr]);
					ctr++;
				}

			// Uploading array
			cuUtils::upload_2D_float(arr_2D_flat_float, dev_arr_2D_flat_float, size_X, size_Y);

			// CUDA Gridding
			dim3 cuBlock(512, 512, 1);
			dim3 cuGrid(size_X / cuBlock.x, size_Y/ cuBlock.y, 1);

			// FFT shift
			cuFFTShift_2D( cuBlock, cuGrid, dev_arr_2D_flat_float, dev_arr_2D_flat_float, size_X);

			// Downloading array
			cuUtils::download_2D_float(arr_2D_flat_float, dev_arr_2D_flat_float, size_X, size_Y);

			// Printing output
			ctr = 0;
			for (int i = 0; i < size_X; i++)
				for (int j = 0; j < size_Y; j++)
				{
					xlSheet->writeNum((ctr) + 2, ((iLoop * 4 ) + 3), arr_2D_flat_float[ctr]);
					ctr++;
				}

			// Dellocating memory
			FREE_MEM_2D_FLOAT(arr_2D_float, size_X, size_Y);
		}

	}
	else
	{
		INFO("No valid xlSheet was created, EXITTING ...");
		EXIT(0);
	}
}
Ejemplo n.º 14
0
void Volume::unifyVolumeDim(volume* iVolume)
{
    int eMaxDim = 0;
    if (iVolume->sizeX >= iVolume->sizeY && iVolume->sizeZ >= iVolume->sizeZ)
        eMaxDim = iVolume->sizeX;
    else if (iVolume->sizeY >= iVolume->sizeX && iVolume->sizeY >= iVolume->sizeZ)
        eMaxDim = iVolume->sizeY;
    else
        eMaxDim = iVolume->sizeZ;

    INFO("MAX DIMENSION : " +  ITS(eMaxDim));

    /* @ Adjusting the power of two dimension condition */
    int eUnifiedDim = 0;
    if (eMaxDim <= 16) eUnifiedDim = 16;
    else if (eMaxDim <= 32) eUnifiedDim = 32;
    else if (eMaxDim <= 64) eUnifiedDim = 64;
    else if (eMaxDim <= 128) eUnifiedDim = 128;
    else if (eMaxDim <= 256) eUnifiedDim = 256;
    else if (eMaxDim <= 512) eUnifiedDim = 512;
    else if (eMaxDim <= 1024) eUnifiedDim = 1024;
    else if (eMaxDim <= 2048) eUnifiedDim = 2048;
    else if (eMaxDim <= 4096) eUnifiedDim = 4096;
    else if (eMaxDim <= 8192) eUnifiedDim = 8192;

    INFO("FINAL UNIFIED VOLUME DIMENSION : " +  ITS(eUnifiedDim));

    /* Calculating the zero-padded area */
    int eX_Pad = (eUnifiedDim - iVolume->sizeX) / 2;
    int eY_Pad = (eUnifiedDim - iVolume->sizeY) / 2;
    int eZ_Pad = (eUnifiedDim - iVolume->sizeZ) / 2;

    INFO("Orginal volume dimensions : "
         + STRG( "[" ) + ITS( iVolume->sizeX ) + STRG( "]" ) + " x "
         + STRG( "[" ) + ITS( iVolume->sizeY ) + STRG( "]" ) + " x "
         + STRG( "[" ) + ITS( iVolume->sizeZ ) + STRG( "]" ));

    INFO("PADDING : "
         + STRG( "[" ) + ITS( eX_Pad ) + STRG( "]" ) + " x "
         + STRG( "[" ) + ITS( eY_Pad ) + STRG( "]" ) + " x "
         + STRG( "[" ) + ITS( eZ_Pad ) + STRG( "]" ));

    /* @ Creating a new flat array for the UNIFIED volume */
    char* eUnfiromFlatVolume = (char*) malloc
            (sizeof(char) * eUnifiedDim * eUnifiedDim * eUnifiedDim);

    // Setting the unified volume
    for (int i = 0; i < iVolume->sizeX; i++)
        for (int j = 0; j < iVolume->sizeY; j++)
            for(int k = 0; k < iVolume->sizeZ; k++)
            {
                int oldIndex = (k * iVolume->sizeX * iVolume->sizeY) +
                        (j * iVolume->sizeX) + i;
                int newIndex = ((k + eZ_Pad) * eUnifiedDim * eUnifiedDim) +
                        ((j + eY_Pad) * eUnifiedDim) + (i + eX_Pad);

                eUnfiromFlatVolume [newIndex] = iVolume->ptrVol_char[oldIndex];
            }

    /* @ Freeing the original input array */
    free(iVolume->ptrVol_char);

    /* @ Poiting to the new UNIFIED flat array */
    iVolume->ptrVol_char = eUnfiromFlatVolume;

    /* @ Adjusting the new volume parameters */
    iVolume->sizeX = eUnifiedDim;
    iVolume->sizeY = eUnifiedDim;
    iVolume->sizeZ = eUnifiedDim;
    iVolume->sizeUni = eUnifiedDim;
}
Ejemplo n.º 15
0
volume* Volume::extractFinalVolume(volume* iOriginaVol,
                                   const subVolDim* iSubVolDim)
{
     INFO("Extracting SUB-VOLUME to be processed in a SINGLE thread");

     INFO("Allocating CUBE array for the original volume : "
          + STRG( "[" ) + ITS( iOriginaVol->sizeX ) + STRG( "]" ) + " x "
          + STRG( "[" ) + ITS( iOriginaVol->sizeY ) + STRG( "]" ) + " x "
          + STRG( "[" ) + ITS( iOriginaVol->sizeZ ) + STRG( "]" ));

    /* @ Allocating cube array for the original volume */
    char*** originalCubeVol = Volume::allocCubeVolume_char
            (iOriginaVol->sizeX, iOriginaVol->sizeY, iOriginaVol->sizeZ);

    INFO("Packing the FLAT array in the CUBE ");

    /* @ Packing the original flat volume in the cube */
    Volume::packCubeVolume(originalCubeVol, iOriginaVol);

    /* @ Allocating the final volume */
    volume* iFinalSubVolume = (volume*) malloc (sizeof(volume));

    iFinalSubVolume->sizeX = iSubVolDim->max_X - iSubVolDim->min_X;
    iFinalSubVolume->sizeY = iSubVolDim->max_Y - iSubVolDim->min_Y;
    iFinalSubVolume->sizeZ = iSubVolDim->max_Z - iSubVolDim->min_Z;

    if (iFinalSubVolume->sizeX == iFinalSubVolume->sizeY
            && iFinalSubVolume->sizeX == iFinalSubVolume->sizeZ)
    {
        INFO("Final SUB-VOLUME has unified dimensions "
             + ITS(iFinalSubVolume->sizeX));

         iFinalSubVolume->sizeUni =  iFinalSubVolume->sizeZ;
    }
    else
    {
        INFO("Final SUB-VOLUME DOESN'T have unified dimensions "
             + ITS(iFinalSubVolume->sizeX));
        EXIT(0);
    }

    iFinalSubVolume->ptrVol_char =
            (char*) malloc (sizeof(char) * iFinalSubVolume->sizeX
                            * iFinalSubVolume->sizeY
                            * iFinalSubVolume->sizeZ);

    INFO("Allocating CUBE array for the final SUB-VOLUME: "
              + STRG( "[" ) + ITS(  iFinalSubVolume->sizeX ) + STRG( "]" ) + " x "
              + STRG( "[" ) + ITS(  iFinalSubVolume->sizeY ) + STRG( "]" ) + " x "
              + STRG( "[" ) + ITS(  iFinalSubVolume->sizeZ ) + STRG( "]" ));

    /* @ Allocating the final cube volume "SUB-VOLUME" */
    char*** finalCubeVol = Volume::allocCubeVolume_char
            (iFinalSubVolume->sizeX, iFinalSubVolume->sizeY, iFinalSubVolume->sizeZ);

    INFO("Extractng the SUB-VOLUME");

    /* @ Extractig the SUB-VOLUME */
    Volume::extractSubVolume(originalCubeVol, finalCubeVol, iSubVolDim);

    for (int y = 0; y < iFinalSubVolume->sizeY; y++)
    {
        for (int x = 0; x < iFinalSubVolume->sizeY; x++)
            free(originalCubeVol[y][x]);

        free(originalCubeVol[y]);
    }
    free(originalCubeVol);
    originalCubeVol = NULL;

    /* @ Dellocating the original cube volume */
   // FREE_MEM_3D_CHAR(originalCubeVol, iOriginaVol->sizeX, iOriginaVol->sizeY, iOriginaVol->sizeZ);

    /* @ Packing the final cube volume in the flat array */
    Volume::packFlatVolume(iFinalSubVolume, finalCubeVol);


    for (int y = 0; y < iFinalSubVolume->sizeY; y++)
    {
        for (int x = 0; x < iFinalSubVolume->sizeY; x++)
            free(finalCubeVol[y][x]);

        free(finalCubeVol[y]);
    }

    free(finalCubeVol);
    finalCubeVol = NULL;

    //FREE_MEM_3D_CHAR(finalCubeVol, iFinalSubVolume->sizeX, iFinalSubVolume->sizeY, iFinalSubVolume->sizeZ);

    INFO("Final volume extraction DONE");

    return iFinalSubVolume;
}