Beispiel #1
0
/*
	_search_fill fills the buffer with random data according to
	a pdf has the entropy specified in the source. It calculates
    the cdf then populate the buffer by searching in the cdf for 
    the random number. Sometimes this approach is called roulette
    algorithm. The binary search is expected to add 8x factor.
*/
int entropy_search_fill(struct source *ds, void *buf, unsigned int size){
	
	int i = 0;
	double pdf[PDF_SIZE];
	double cdf[PDF_SIZE];
	unsigned char symbols_table[PDF_SIZE];

	//Calculate pdf according to the given entropy
	generate_pdf(pdf, PDF_SIZE, ds-> s_entropy);
#ifndef _FB_FILEBENCH_H
	print_pdf(pdf, 5);
	printf("PDF entropy is: %f\n" ,pdf_entropy(pdf, PDF_SIZE));
#endif
	//Calculate cdf from the pdf
	calculate_cdf(pdf, PDF_SIZE, cdf);

	//initializing the symbol table
	for(i=0; i< PDF_SIZE; i++)
		symbols_table[i] = (unsigned char)i;

	//shuffle the symbols table
	permutate(symbols_table, PDF_SIZE);

	for(i=0; i < size; i++){
		((unsigned char*)buf)[i] = symbols_table[binary_search(rand()/(double)RAND_MAX, cdf, PDF_SIZE)];
	}
	return 0;
}
Beispiel #2
0
int     main    (int argc, char *argv [])
{
        char    buf [BUFSIZ];           /* a buffer                     */
        char    *tokptr, *strptr = buf; /* a pointer to the buffer      */
        int     c;                      /* general-purpose              */
        int     SkipLine = 0;           /* pattern match checker        */
        int     idx;                    /* token index                  */
        FILE    *infp;                  /* input file                   */
        FILE    *outfp;                 /* output file                  */

        /*     Check for input file                                     */
        if (argc < 2)   show_help();

        /*      process the command line arguments                      */
        while ((c = getopt (argc, argv, "?vc:r:f:")) != EOF) {
                switch (c) {
                        case '?':
                                show_help();
                                break;
                        case 'v':
                                vopt = TRUE;
                                break;
                        case 'c':
                                CDFopt = TRUE;
                                CDFSelect = atoi(optarg);
                                break;
                        case 'r':
                                RWBSSelect = atoi(optarg);
                                break;
                        case 'f':
                                FieldSelectNo = atoi(optarg);
                                break;
                        default:
                                show_help();
                                return (0);
                                break;
                }
        }

        if (RWBSSelect == RWBS_WRITE)
        {
               RWBS_ext = "_W"; 
        }
        else if (RWBSSelect == RWBS_READ)
        {
               RWBS_ext = "_R";
        }
        else if (RWBSSelect == RWBS_RD_WR)
        {
               RWBS_ext = "_RW";
        } 

        /*      now process any arguments supplied...   */
        while (optind != argc) {
                if (vopt) {
                        (void) fprintf (stderr, "Processing %s...\n", argv [optind]);
                }
                if (CDFopt){
                        calculate_cdf(argv [optind], CDFSelect);
                        break; 
                        return 0;
                }
                /*      open the input file             */
                if ((infp = fopen (argv [optind], "r")) == (FILE *) NULL) {
                        (void) fprintf (stderr, "%s:\tcan't open %s\n", 
                                                            argv [0], argv [optind]);
                        exit (EXIT_FAILURE);
                }
                snprintf(out_file, sizeof out_file, "%s%s%s", argv [optind], RWBS_ext,  out_ext);
                if ((outfp = fopen (out_file, "w")) == (FILE *) NULL){
                        (void) fprintf (stderr, "%s:\tcan't open %s\n", 
                                                            argv [0], out_file);
                        exit (EXIT_FAILURE);
                }
                /*      get a line from the input file  */
                while (fgets (buf, sizeof (buf), infp) != (char *) NULL) {
                        /*      we have to point to buf */
                        strptr = buf;
                        /* set SkipLine to zero for next iteration */
                        SkipLine = 0;
                        /*      take the line apart     */
                        idx = 1; 
                        while ((tokptr = strtok (strptr, separator)) != (char *) NULL) {
                               if (idx == 1)  // Dev Maj/Min No 
                               {
                                       idx++;
                               } 
                               else if (idx == 2) // CPU No
                               {
                                       idx++;
                               } 
                               else if (idx == 3) // Sequence No
                               {
                                       idx++; 
                               } 
                               else if (idx == 4) // TIME 
                               {
                                       strcpy (TIME, tokptr);
                                       idx++; 
                               } 
                               else if (idx == 5) // Process No
                               {
                                       idx++; 
                               }
                               else if (idx == 6) // Command
                               {
                                       strcpy (COMMAND, tokptr);
                                       idx++; 
                               }
                               else if (idx == 7) // RWBS
                               {
                                       strcpy (RWBS, tokptr);
                                       idx++; 
                               }
                               else if (idx == 8) // Sector No
                               {
                                       strcpy (SECTORNO, tokptr);
                                       if (match ("[*", tokptr))
                                              SkipLine = 1;
                                       idx++; 
                               }
                               else if (idx == 9) // + Separator but check for [0]
                               {
                                       if (!match ("+", tokptr))
                                              SkipLine = 1;
                                       idx++; 
                               }
                               else if (idx == 10) // Length 
                               {
                                       strcpy (LENGTH, tokptr);
                                       idx++; 
                               }
                               else if (idx == 11) // ( separator or [0]
                               {
                                       if (!match ("(", tokptr))
                                              SkipLine = 1;
                                       idx++; 
                               }
                               else if (idx == 12) // Duration
                               {
                                       strcpy (DURATION, tokptr);
                                       idx++; 
                               }
                               /*      null the pointer        */
                                strptr = (char *) NULL;
                        }
                        /* printout only if the line has proper result */
                        if (SkipLine == 0 )
                        {
                                if (RWBSSelect == RWBS_WRITE && match("*W*", RWBS) 
                                          && match("*C*", COMMAND)) 
                                {
                                       FieldSelection(); 
                                }
                                else if (RWBSSelect == RWBS_READ && match("*R*", RWBS)
                                          && match("*C*", COMMAND)) 
                                {
                                       FieldSelection(); 
                                }
                                else if (RWBSSelect == RWBS_RD_WR && match("*C*", COMMAND)) 
                                {
                                       FieldSelection(); 
                                } 
                                (void) fprintf (outfp, "%s\n", row_of_fields);
                        }
                }

                /*      close the input file            */
                if (fclose (infp)) {
                        (void) fprintf (stderr, "%s:\tcan't close %s\n", 
                                                            argv [0], argv [optind]);
                        exit (EXIT_FAILURE);
                }
                if (fclose (outfp)) {
                        (void) fprintf (stderr, "%s:\tcan't close %s\n",
                                                            argv [0], out_file);
                        exit (EXIT_FAILURE);
                }
                /*      bumpt the counter for next file */
                optind++;
        }
        return (0);
}
int main(int argc, char **argv) {
  float *d_luminance;
  unsigned int *d_cdf;

  size_t numRows, numCols;
  unsigned int numBins;

  std::string input_file;
  std::string output_file;
  std::string reference_file;
  double perPixelError = 0.0;
  double globalError   = 0.0;
  bool useEpsCheck = false;

  switch (argc)
  {
	case 2:
	  input_file = std::string(argv[1]);
	  output_file = "output.png";
	  break;
	case 3:
	  input_file  = std::string(argv[1]);
      output_file = std::string(argv[2]);
	  break;
	default:
      std::cerr << "Usage: ./tone input_file [output_filename] [reference_filename]" << std::endl;
      exit(1);
  }

  //load the image and give us our input and output pointers
  preProcess(&d_luminance, &d_cdf,
             &numRows, &numCols, &numBins, input_file);

  GpuTimer timer;
  float min_logLum, max_logLum;
  min_logLum = 0.f;
  max_logLum = 1.f;
  timer.Start();

  //call the students' code
  calculate_cdf(d_luminance, d_cdf, min_logLum, max_logLum,
                               numRows, numCols, numBins);
  timer.Stop();
  cudaDeviceSynchronize(); 
  int err = printf("Your code ran in: %f msecs.\n", timer.Elapsed());

  if (err < 0) {
    //Couldn't print! Probably the student closed stdout - bad news
    std::cerr << "Couldn't print timing information! STDOUT Closed!" << std::endl;
    exit(1);
  }

  float *h_luminance = (float *) malloc(sizeof(float)*numRows*numCols);
  unsigned int *h_cdf = (unsigned int *) malloc(sizeof(unsigned int)*numBins);

  cudaMemcpy(h_luminance, d_luminance, numRows*numCols*sizeof(float), cudaMemcpyDeviceToHost);

  //check results and output the tone-mapped image
  postProcess(output_file, numRows, numCols, min_logLum, max_logLum);

  cleanupGlobalMemory();

  return 0;
}