How to load JPEG image in CUDA?

Hello, everyone!
I manged to write a simple CUDA program, but now, when I have to import JPEG file in my CUDA program, there are very serious problems. I tried with jig.org linbraries but it looks like you can’t mix two compilers in CUDA application cause it says “some.lib already difinied in some.lib”. Can you please help me out, or at least route me to some helpfull page? Thanks

Can you at least tell me is it possible to read jpeg file in CUDA?
Thanks

I think you will want to read a jpeg file in C. CUDA is the part that runs on the GPU and that does not read files.

#include <stdio.h>

#include <cutil_inline.h>

#include <jerror.h>   // headers 

#include <jconfig.h>  //		 for

#include <jmorecfg.h> //			  JPEG 

#include <jpeglib.h>  //				   LIB

#pragma comment (lib, "jpeg.lib") // Library that I constructed using jig.org source code

#define Width 24

#define Tile_Width 12

#define tip int

__global__ void MatrixMul(int *Md, int *Nd, int *Pd){

	int x=blockIdx.x*Tile_Width+threadIdx.x; 

	int y=blockIdx.y*Tile_Width+threadIdx.y;

	int pom=0;

	for(int k=0;k<Width;k++){	

		pom+=Md[y*Width+k]*Nd[k*Width+x];  

		Pd[y*Width+x]=pom;

	

	}

}

int main(int argc, char** argv) {

		tip *Md,*Nd,*Pd;	// Pointers to GPU memory

		tip *M,*N,*P;		// Pointers to CPU memory

		int i,j;

		tip Amount=Width*Width*sizeof(tip);

		char a;

	

		struct jpeg_decompress_struct cinfo;

		struct jpeg_error_mgr jerr;

		FILE * infile;

		char  *picture=NULL;

		printf("Input the name of the picture to be opened:\n");

		scanf("%s",picture);

		infile = fopen(picture, "rb");

		if (infile == NULL) {

			fprintf(stderr, "can't open %s\n", picture);

			exit(1);

		}

		cinfo.err = jpeg_std_error(&jerr);  // E

		jpeg_create_decompress(&cinfo);		// R

		jpeg_stdio_src(&cinfo, infile);		// R

		jpeg_read_header(&cinfo, TRUE);		// O

		

		

		jpeg_start_decompress(&cinfo);	  // R

		

		//jpeg_destroy();

		

	// Allocation of memory for CPU based matrix M,N and P

		M = (tip*) malloc((Amount));

		N = (tip*) malloc((Amount));

		P = (tip*) malloc((Amount));

	// Initialization of matrices M and N

		for(i=0;i<Width;i++){

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

				

				if(j==i){

					M[i*Width+j]=1;

					N[i*Width+j]=1;

				}

				if(i!=j){

					M[i*Width+j]=0;

					N[i*Width+j]=0;

				}

			}

			}

		

// Allocation of GPU based memory for Md, Nd and Pd matrices

		cudaMalloc((void**)&Md,Amount);

		cudaMemcpy(Md,M,Amount,cudaMemcpyHostToDevice);

		cudaMalloc((void**)&Nd,Amount);

		cudaMemcpy(Nd,N,Amount,cudaMemcpyHostToDevice);

		cudaMalloc((void**)&Pd,Amount);

// Setting up parameteres for kernel invocation

		dim3 dimGrid(2,2,1);

		dim3 dimBlock(Width/2,Width/2,1);	

// Kernel invocation

		MatrixMul<<<dimGrid,dimBlock>>>(Md,Nd,Pd);

// Return of results from GPu to CPU

		cudaMemcpy(P,Pd,(Width*Width*sizeof(tip)),cudaMemcpyDeviceToHost);

	

		// Printing of results

			for(i=0;i<Width;i++){

				printf("\n");

				i>9? printf("%d. ",i):printf("%d.  ",i);

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

				  

					printf("[%d]",P[i*Width+j]);

				}

			}

					printf("\n");

					printf("Line just to hold console app win, ...\n");

					scanf("%d",&a);

}

I did, using the jig.org library, and then it gives me this error:

Error 1 error LNK2005: __iob_func already defined in LIBCMT.lib(_file.obj) MSVCRT.lib

Error 2 error LNK2005: fprintf already defined in LIBCMT.lib(fprintf.obj) MSVCRT.lib

Error 3 error LNK2005: exit already defined in LIBCMT.lib(crt0dat.obj) MSVCRT.lib

Error 4 error LNK2005: getenv already defined in LIBCMT.lib(getenv.obj) MSVCRT.lib

Error 5 error LNK2005: free already defined in LIBCMT.lib(free.obj) MSVCRT.lib

Error 6 error LNK2005: malloc already defined in LIBCMT.lib(malloc.obj) MSVCRT.lib

Error 8 fatal error LNK1169: one or more multiply defined symbols found …/…/bin/win64/Debug/asyncAPI.exe

Yes, I forgot to mention, I use VS 2008 on Win7 x64 with GeForce 9600m GT. Also, 4GB of RAM

Thanks

libcmt bugs usually vanish into thin air, if u merely change the order of linking (in the link command line). Dont ask me why.

If you can specify where exactly is that command line? I have been searching for it but found only some line in linker that can’t be changed. Thanks

one of the following Visual C++ linker switches

/IGNOREDEFAULTLIB:LIBCMT

or

/IGNOREDEFAULTLIB:MSVCRT

might do the trick. It’s usually a problem when different object files get linked together which have been built with
different /MT or /MD switches.

Oops, I think this reply got threaded under the wrong parent posting.

Proj properties - linker - command line — You should be able to add, delete things from it…

OK, guys, this is the picture:

http://www.mediafire.com/imageview.php?quickkey=fkmwmoid2z3

Nothing worked of the above two things you suggested, but thank you very much for support
If you could only look at the problem and help;-), thank you

hello, again
I maneged to solve the issue. What i did was to add another static library but one that was made with MDd and add this line of code /NODEFAULTLIB:LIBCMT.lib to LInker->Command Line
Hope it really is the solution not just hiding an error massage!
Thank you all, really

Now, I get following error: C\bin\win64\Debug\cudart64_30_14.dll’, Binary was not built with debug information.
I think I’ll give up and use BMP format for incoming pictures, thanks all

P.S. Can anyone give me a link to already builed jpeglib for VS 2008 x64 on the net?
Thanks