コード例 #1
0
ファイル: k_paging.c プロジェクト: Rhoin/RhKernel-Old-
void paging_init()
{
	uint32_t memsize = getTotalMem();
	
	nframes = memsize / FRAME_BLOCK_SIZE;
	pFrames = (uint32_t)malloc(INDEX_BIT(nframes));
	memset(pFrames,0,INDEX_BIT(nframes));
	
	kerneldir = (page_dir_t*)malloc_a(sizeof(page_dir_t));
	curdir = kerneldir;
	
	//You may ask why I didnt use for loop
	//Because kernel end will change.If I use for lopp dont take effect from kernel
	//end change.Which can give us unexcepted results
	int i = 0;
	while(i < place_addr)
	{
		allocFrame(getFrame(i,TRUE,kerneldir),FALSE,FALSE);
		i += FRAME_BLOCK_SIZE;
	}
	
	//isr_install_interrupt(16,page_handle);
	
	paging_changedir(kerneldir);
}
コード例 #2
0
ファイル: alloc.c プロジェクト: celskeggs/libca
void *malloc_zeroed_a(memory_arena *arena, ulen size) {
	if (size == 0) {
		return NULL;
	}
	if (arena->alloc_zeroed == NULL) {
		void *out = malloc_a(arena, size);
		memset(out, 0, size);
		return out;
	}
	void *out = arena->alloc_zeroed(arena->_arena_custom_data, size);
	if (out == NULL) {
		panic_static("OOM");
	}
	return out;
}
コード例 #3
0
ファイル: alloc.c プロジェクト: celskeggs/libca
void *realloc_a(memory_arena *arena, void *memory, ulen size) {
	if (size == 0) {
		if (memory != NULL) {
			free_a(arena, memory);
		}
		return NULL;
	} else if (memory == NULL) {
		return malloc_a(arena, size);
	}
	if (arena->realloc == NULL) {
		panic_static("attempt to realloc in unsupporting arena");
	}
	void *out = arena->realloc(arena->_arena_custom_data, memory, size);
	if (out == NULL) {
		panic_static("OOM");
	}
	return out;
}
コード例 #4
0
ファイル: analyzePoT.cpp プロジェクト: petri33/XBranch-1
int analyze_pot(float *PowerSpectrum, int NumDataPoints, ChirpFftPair_t &cfft, int offset)
{
  // This function analyses Power over Time for the current data block.
  // The PoT array  is created by taking an array of power spectra (a
  // standard row-major 2D array)  and extracting the PoT as column-major
  // data.  We essentialy turn the array on its side.
  
  int  retval = 0,
    i,
    FftLength=cfft.FftLen,  // Current FFT length
    ThisPoT,          // index of current PoT along the freq axis
    PoTLen,           // complement of FFT length - determines time res
    PulsePoTLen,      // length of PoT segment passed to pulse finders
    Overlap,          // PoT segment overlap in bins
    TOffset,          // index into ThisPoT of current pulse segment
    PulsePoTNum  = 0, // the oridinal position of a pulse PoT w/in a full PoT
    NumPulsePoTs = 0, // the number of pulse PoTs w/in a full PoT.  This is
    //   constant regardless of FFT or PoT length and is
    //   determined by slew rate.
    AdvanceBy;        // the number of bins to advance for the next pulse PoT
  
  float ProgressAddFactor = 0.0,    // sum of progress adds for ThisPoT
    ProgressPerPulsePoT = 0.0;  // for local progress display
  
  bool SkipGauss   = false,
    SkipPulse   = false,
    SkipTriplet = false,
    TOffsetOK   = true;
  
  static float  *GaussPoT = NULL,
    *PulsePoT = NULL;
  
#ifdef DEBUG_POT
  fprintf(stderr, "========= FftLength = %d =========\n", FftLength);
#endif
  
  PoTLen              = NumDataPoints / FftLength;               // in bins
  GetPulsePoTLen(PoTLen, &PulsePoTLen, &Overlap);     // in bins
  AdvanceBy  = PulsePoTLen - Overlap;     // in bins		
  
  // Max limits how *slow* the slewrate can be, while Min limits how
  // *fast* the slewrate can be.  Max is limited only by the client
  // memory budget.
  if(PulsePoTLen > PoTInfo.TripletMax || PulsePoTLen < PoTInfo.TripletMin)
    SkipTriplet = true;
  SkipGauss = !(cfft.GaussFit);
  SkipPulse = !(cfft.PulseFind);
  
  if(!SkipPulse || !SkipTriplet) 
    {
      // NumPulsePoTs is the number of PoT segments that we pass to the pulse
      // detectors per frequency bin.  ProgressPerPulsePoT is the inverse of
      // number of pulse detection segments in the entire data block, taking
      // into account that we skip the first (DC) frequency bin.  An assumption
      // is made here that minimum pulse/triplet PoT length will always be
      // greater than 1. Otherwise, AdvanceBy can become zero and a divide by
      // zero can occur.  The assumption is also made that FftLength is always
      // greater than 1!
      NumPulsePoTs = 1 + (PoTLen-PulsePoTLen)/AdvanceBy + ((PoTLen-PulsePoTLen)%AdvanceBy ? 1 : 0);
      ProgressPerPulsePoT = (float)1 / ((FftLength - 1) * NumPulsePoTs);
    }
  
#ifdef DEBUG_POT
  fprintf(stderr, "SlewRate = %f\n", PoTInfo.SlewRate);
  fprintf(stderr, "PoTLen = %d\n", PoTLen);
  fprintf(stderr, "MaxPoTLen = %d\n", PoTInfo.MaxPoTLen);
  fprintf(stderr, "PoTDuration = %f\n", PoTInfo.WUDuration);
  fprintf(stderr, "BeamRate = %f\n", PoTInfo.BeamRate);
  fprintf(stderr, "PulsePoTLen = %d\n", PulsePoTLen);
  fprintf(stderr, "Overlap = %d\n", Overlap);
  fprintf(stderr, "AdvanceBy = %d\n", AdvanceBy);
  fprintf(stderr, "min_slew = %f\n", PoTInfo.min_slew);
  fprintf(stderr, "max_slew = %f\n", PoTInfo.max_slew);
  fprintf(stderr, "PulseOverlapFactor = %f\n", PoTInfo.PulseOverlapFactor);
  fprintf(stderr, "PulseBeams = %f\n", PoTInfo.PulseBeams);
  fprintf(stderr, "PulseThresh = %f\n", PoTInfo.PulseThresh);
  fprintf(stderr, "PulseMax = %d\n", PoTInfo.PulseMax);
  fprintf(stderr, "PulseMin = %d\n", PoTInfo.PulseMin);
  fprintf(stderr, "PulseFftMax = %d\n", PoTInfo.PulseFftMax);
  fprintf(stderr, "TripletThresh = %f\n", PoTInfo.TripletThresh);
  fprintf(stderr, "TripletMax = %d\n", PoTInfo.TripletMax);
  fprintf(stderr, "TripletMin = %d\n", PoTInfo.TripletMin);
#endif
  
#ifndef USE_PULSE
  SkipPulse = TRUE;
  static int doneprintnopulsefind = 0;
  if(!doneprintnopulsefind) 
    { 
      fprintf(stderr,"SkipPulse is set to TRUE: Not doing Pulsefinds.\n");
      doneprintnopulsefind = TRUE;
    }
#endif
#ifndef USE_TRIPLET
  SkipTriplet = TRUE;
#endif
  
  // Get memory fot the PoT arrays. The PoT array for gausian analysis is
  // of set size.  The PoT array for pulse analysis is sized to cover
  // PulseBeams beams, regardless of whether this violates either the
  // triplet or pulse limits on array size.
  if(!GaussPoT) 
    {
      GaussPoT = (float *)malloc_a(swi.analysis_cfg.gauss_pot_length * sizeof(float), MEM_ALIGN);
      if(GaussPoT == NULL) 
	{
	  SETIERROR(MALLOC_FAILED, "GaussPoT == NULL");
	}
    }
  if(!PulsePoT) 
    {
      PulsePoT = (float *)calloc_a(PoTInfo.MaxPoTLen+3, sizeof(float), MEM_ALIGN);
      if(PulsePoT == NULL) 
	{
	  SETIERROR(MALLOC_FAILED, "PulsePoT == NULL");
	}
    }
  bool b_gaussStarted = false;  
  // Look for gaussians ---------------------------------------------------
  if(!SkipGauss && (analysis_state.PoT_activity == POT_DOING_GAUSS ||
		    analysis_state.PoT_activity == POT_INACTIVE)) 
    {
      
#ifdef BOINC_APP_GRAPHICS
      if (!nographics())
	strcpy(sah_graphics->status, "Searching for Gaussians");
#endif
      
      // If we are back from being interrupted in the middle of gaussian PoT
      // analysis, load state and continue.  Otherwise start anew, skipping
      // the DC (0) bin.
      if(analysis_state.PoT_activity == POT_DOING_GAUSS) 
	{
	  ThisPoT = analysis_state.PoT_freq_bin;
	} 
      else 
	{
	  ThisPoT = 1; // skip the DC bin on start of new cfft pair
	}
      
      // Initial display of local Progress / CPU time. Assumes that
      // we start ThisPoT at 1 each time in!
#ifdef BOINC_APP_GRAPHICS
      if (!nographics())
	sah_graphics->local_progress = ((float)ThisPoT-1)/(FftLength-1);
#endif
      
#ifdef USE_CUDA
      //#ifndef CUDAACC_EMULATION
      if(gSetiUseCudaDevice)
	{
	  //TODO: remove the autocorr_fftlen test when v6 fully deprecated.
	  bool noscore = false; //swi.analysis_cfg.autocorr_fftlen!=0 && gaussian_count!=0;
	  
	  //cudaAcc_Gaussfit(FftLength, best_gauss->score, noscore);
	  //printf("GaussFitStart\r\n");
	  b_gaussStarted = true; // started earlier
	  //cudaAcc_GaussfitStart(FftLength, best_gauss->score, noscore);
	  
	  if(PoTLen > swi.analysis_cfg.gauss_pot_length)
	    analysis_state.FLOP_counter+=((double)NumDataPoints+swi.analysis_cfg.gauss_pot_length * (FftLength-1)); // GetFixedPoT
	  // There are FftLength - 1 fixed PoTs for a chirp/fft pair, and for each fixed PoT full analysis would do
	  // (1 + (PoTInfo.GaussTOffsetStop - PoTInfo.GaussTOffsetStart)) GetPeak and GetTrueMean operations.
	  // Use (1 - PoTInfo.GaussSigma*0.09) empirically found to represent fraction of PoTs which don't
	  // take either of the two early out paths.
	  double CorrWt = (1.0 - PoTInfo.GaussSigma*0.09) * (FftLength - 1) * (1 + (PoTInfo.GaussTOffsetStop - PoTInfo.GaussTOffsetStart));
	  analysis_state.FLOP_counter+=6.0*floor(PoTInfo.GaussSigma+0.5) * CorrWt; // GetPeak
	  analysis_state.FLOP_counter+=(double)(floor(PoTInfo.GaussSigma+0.5) * 3.911+5) * CorrWt; // GetTrueMean
	  // Estimate one in twenty fit positions look good enough to be checked further.
	  analysis_state.FLOP_counter+= 0.05 * (20.0*swi.analysis_cfg.gauss_pot_length+5.0) * CorrWt; // GetChiSq / 20
	  
	  
	  progress += ProgressUnitSize * GaussianProgressUnits();
	  progress=std::min(progress,1.0); // prevent display of > 100%
	  fraction_done(progress,remaining);
	  
	}
      //#endif CUDAACC_EMULATION
      else
	{
#endif //USE_CUDA
	  // loop through frequencies                            
	  /*	  for(; ThisPoT < FftLength; ThisPoT++) 
	    {
	      
	      // Create PowerOfTime array for gaussian fit
	      retval = GetFixedPoT(
				   PowerSpectrum,
				   NumDataPoints,
				   FftLength,
				   GaussPoT,
				   swi.analysis_cfg.gauss_pot_length,
				   ThisPoT
				   );
	      if (retval)
		continue;
	      
	      retval = GaussFit(GaussPoT, FftLength, ThisPoT);
	      if (retval)
		SETIERROR(retval,"from GaussFit");
	      
	      
	      
	      progress += ProgressUnitSize * GaussianProgressUnits() / (float)(FftLength - 1);
	      progress=std::min(progress,1.0); // prevent display of > 100%
	      fraction_done(progress,remaining);
	      
	      // At the end of each frequency bin we update progress and save state.
#ifdef BOINC_APP_GRAPHICS
	      if (!nographics()) 
		{
		  sah_graphics->local_progress = ((float)ThisPoT)/(FftLength-1);
		}
#endif  
	      analysis_state.PoT_freq_bin = ThisPoT;
	      analysis_state.PoT_activity = POT_DOING_GAUSS;
	      retval = checkpoint();
	      if (retval)
		SETIERROR(retval,"from checkpoint()");
	    }   // end loop through frequencies
	  */  
#ifdef USE_CUDA
	}
#endif //USE_CUDA
      analysis_state.PoT_freq_bin = -1;
      analysis_state.PoT_activity = POT_INACTIVE;
    }   // end looking for gaussians
  
  
  // Look for pulses -------------------------------------------------------
  if(!SkipPulse || !SkipTriplet) 
    {
      
#ifdef BOINC_APP_GRAPHICS
      if (!nographics())
	{
	  strcpy(sah_graphics->status, "Searching for Pulses / Triplets");
	  // init local progress for pulse search
	  sah_graphics->local_progress = 0;
	}
#endif
      
      
      // If we are back from being interrupted in the middle of pulse PoT
      // analysis, load state and continue.  Otherwise start anew, skipping
      // the DC (0) bin.
      if(analysis_state.PoT_activity == POT_DOING_PULSE) 
	{
	  ThisPoT = analysis_state.PoT_freq_bin;
	} 
      else 
	{
	  ThisPoT = 1; // skip the DC bin on start of new cfft pair
	}
      
      PulsePoTNum = 0;
      
#ifdef BOINC_APP_GRAPHICS
      // Inital display of Local Progress
      if(!nographics()) 
	{
	  sah_graphics->local_progress = (((ThisPoT-1) * NumPulsePoTs) +
					  PulsePoTNum)                   *
	    ProgressPerPulsePoT;
	}
#endif
      
#ifdef USE_CUDA
      if(gSetiUseCudaDevice)
	{	
	  /*
	    if(!SkipTriplet || !SkipPulse) // do beforehand on fftstreamX
	    {
	    //	    CUDASYNC;
	    //printf("CalculateMean\r\n");
	    cudaAcc_calculate_mean(PulsePoTLen, 0, AdvanceBy, FftLength);
	    }
	    
	    if(!SkipPulse) 
	    {
	    //printf("FindPulses\r\n");
	    cudaAcc_find_pulses((float) best_pulse->score, PulsePoTLen, AdvanceBy, FftLength);
	    }
	    
	    if(!SkipTriplet) 
	    {
	    //printf("FindTriplets\r\n");
	    cudaAcc_find_triplets(PulsePoTLen, (float)PoTInfo.TripletThresh, AdvanceBy, FftLength);
	    }
	  */
	  /*
		  timespec t1, t2;
		  t1.tv_sec = 0;
		  t1.tv_nsec = 5000;
		  while(cudaEventQuery(summaxDoneEvent) != cudaSuccess)
		    nanosleep(&t1, &t2);

	   */
	  
	  int gflags = 0;
	  if(b_gaussStarted)
	    {
	      //printf("fetchGaussFitFlags\r\n");
	      b_gaussStarted = false;
	      gflags = cudaAcc_fetchGaussfitFlags(FftLength, best_gauss->score);
	    }
	  
	  //printf("fetchTripletAndPulseFlags\r\n");
	  int has_dataT = 0, has_dataP = 0;
	  if(!SkipTriplet)
	    has_dataT = cudaAcc_fetchTripletFlags(SkipTriplet, PulsePoTLen, AdvanceBy, FftLength, offset);
	  
  	  if(gflags > 0)
	    {
	      //printf("ProcessGaussFit\r\n");
	      cudaAcc_processGaussFit(FftLength, best_gauss->score);
	    }
	  
	  if(!SkipTriplet)
	    {
	      if((has_dataT & 1) && !(has_dataT & 4)) // has triplet data and no error in triplet
		{
		  //printf("processTripletResults\r\n");
		  cudaAcc_processTripletResults(PulsePoTLen, AdvanceBy, FftLength);
		}
	      
	      analysis_state.FLOP_counter+=(10.0 + PulsePoTLen) * NumPulsePoTs * (FftLength - 1);
	      //  ! hard to estimate, so be generous and use 9
	      analysis_state.FLOP_counter+=810.0; // (10.0*numBinsAboveThreshold*numBinsAboveThreshold);
	      progress += ProgressUnitSize * TripletProgressUnits();
	    }		
	  
	  if(!SkipPulse)
	    has_dataP = cudaAcc_fetchPulseFlags(SkipTriplet, PulsePoTLen, AdvanceBy, FftLength, offset);
	  
	  if(!SkipPulse) 
	    {
	      if((has_dataP & 2) && !(has_dataP & 8)) // has pulse data and no error in pulse
		{
		  //printf("processPulseResults\r\n");
		  cudaAcc_processPulseResults(PulsePoTLen, AdvanceBy, FftLength);
		}
	      analysis_state.FLOP_counter+=(PulsePoTLen*0.1818181818182+400.0)*PulsePoTLen * NumPulsePoTs * (FftLength - 1);
	      progress += ProgressUnitSize * PulseProgressUnits(PulsePoTLen, FftLength - 1);
	    }
	  
	  //#ifndef CUDAACC_EMULATION
	  //if(!SkipTriplet)
	  //	  cudaAcc_fetchTripletAndPulseFlags(SkipTriplet, SkipPulse, PulsePoTLen, AdvanceBy, FftLength);
	  progress=std::min(progress,1.0); // prevent display of > 100%
	  fraction_done(progress,remaining);
	  //if(!SkipTriplet)
	  //  cudaAcc_processTripletResults(PulsePoTLen, AdvanceBy, FftLength);
	  //#endif //CUDAACC_EMULATION
	}
      //      else
      //	{
#endif //USE_CUDA
	  
	  // loop through frequencies
	  /*	  for(; ThisPoT < FftLength; ThisPoT++) 
	    {
	      // loop through time for each frequency.  PulsePoTNum is
	      // used only for progress calculation.
	      for(TOffset = 0, PulsePoTNum = 1, TOffsetOK = true;
		  TOffsetOK;
		  PulsePoTNum++, TOffset += AdvanceBy) 
		{
		  
		  // Create PowerOfTime array for pulse detection.  If there
		  // are not enough points left in this PoT, adjust TOffset
		  // to get the latest possible pulse PoT.
		  if(TOffset + PulsePoTLen >= PoTLen) 
		    {
		      TOffsetOK = false;
		      TOffset = PoTLen - PulsePoTLen;
		    }
		  if (use_transposed_pot) 
		    {
		      memcpy(PulsePoT, &PowerSpectrum[ThisPoT * PoTLen + TOffset], PulsePoTLen*sizeof(float));
		    } 
		  else 
		    {
		      for(i = 0; i < PulsePoTLen; i++) 
			{
			  PulsePoT[i] = PowerSpectrum[ThisPoT + (TOffset+i) * FftLength];
			}
		    }
		  
		  if(!SkipTriplet) 
		    {
		      retval = find_triplets(PulsePoT,
					     PulsePoTLen,
					     (float)PoTInfo.TripletThresh,
					     TOffset,
					     ThisPoT);
		      if (retval)
			SETIERROR(retval,"from find_triplets()");
		    }
		  //#ifndef CUDAACC_EMULATION
		  if(!SkipPulse) 
		    {
		      retval = find_pulse(PulsePoT,
					  PulsePoTLen,
					  (float)PoTInfo.PulseThresh,
					  TOffset,
					  ThisPoT
					  );
		      if (retval)
			SETIERROR(retval,"from find_pulse()");
		    }
		  //#endif //CUDAACC_EMULATION
		  
		  // At the end of each pulse PoT we update progress.  Progress
		  // will thus get updted several times per frequency bin.
#ifdef BOINC_APP_GRAPHICS
		  if (!nographics())
		    {
		      sah_graphics->local_progress = (((ThisPoT-1) * NumPulsePoTs) +
						      PulsePoTNum)                   *
			ProgressPerPulsePoT;
		    }
#endif
		  if(!SkipTriplet) 
		    {
		      progress += (ProgressUnitSize * TripletProgressUnits()) /
			(float)(FftLength - 1) / NumPulsePoTs;
		    }
		  if(!SkipPulse) 
		    {
		      progress += (ProgressUnitSize * PulseProgressUnits(PulsePoTLen, FftLength - 1)) /
			(float)(FftLength - 1) / NumPulsePoTs;
		      
		    }
		  progress=std::min(progress,1.0); // prevent display of > 100%
		  fraction_done(progress,remaining);
		  
		}  // end loop through time for each frequency
	      
	  	      // At the end of each frequency bin we save state.
	      analysis_state.PoT_activity = POT_DOING_PULSE;
	      analysis_state.PoT_freq_bin = ThisPoT;
	      retval = checkpoint();
	      if (retval)
		SETIERROR(retval,"from checkpoint()");
	    }   // end loop through frequencies
	  analysis_state.PoT_freq_bin = -1;
	  analysis_state.PoT_activity = POT_INACTIVE;
#ifdef USE_CUDA
	}
#endif //USE_CUDA
	  */

    }   // end looking for pulses			
  
  if(b_gaussStarted) // process results late
    {
      //printf("late GaussBlock\r\n");
      
      int flags = cudaAcc_fetchGaussfitFlags(FftLength, best_gauss->score);
      
      if(flags>0)
	cudaAcc_processGaussFit(FftLength, best_gauss->score);
    }
  
  return (retval);   // no error return point
}
コード例 #5
0
ファイル: analyzeFuncs.cpp プロジェクト: dcarrion87/boinc-rpi
int seti_analyze (ANALYSIS_STATE& state) {
    sah_complex* DataIn = state.savedWUData;
    int NumDataPoints = state.npoints;
    sah_complex* ChirpedData = NULL;
    sah_complex* WorkData = NULL;
    float* PowerSpectrum = NULL;
    float* tPowerSpectrum; // Transposed power spectra if used.
    float* AutoCorrelation = NULL;

    use_transposed_pot= (!notranspose_flag) &&
                        ((app_init_data.host_info.m_nbytes != 0)  &&
                        (app_init_data.host_info.m_nbytes >= (double)(96*1024*1024)));
    int num_cfft                  = 0;
    float chirprate;
    int last_chirp_ind = - 1 << 20, chirprateind;

    double progress_diff, progress_in_cfft, cputime0=0;
    int retval=0;

    if (swi.analysis_cfg.credit_rate != 0) LOAD_STORE_ADJUSTMENT=swi.analysis_cfg.credit_rate;

#ifndef DEBUG
    int icfft;
#endif
    int NumFfts, ifft, fftlen;
    int CurrentSub;
    int FftNum, need_transpose;
    unsigned long bitfield=swi.analysis_cfg.analysis_fft_lengths;
    unsigned long FftLen;
    unsigned long ac_fft_len=swi.analysis_cfg.autocorr_fftlen;

#ifdef USE_IPP
    IppsFFTSpec_C_32fc* FftSpec[MAX_NUM_FFTS];
    int BufSize;

    ippStaticInit();   // initialization of IPP library
#elif defined(USE_FFTWF)
    // plan space for fftw
    fftwf_plan analysis_plans[MAX_NUM_FFTS];
    fftwf_plan autocorr_plan;
#else
    // fields need by the ooura fft logic
    int * BitRevTab[MAX_NUM_FFTS];
    float * CoeffTab[MAX_NUM_FFTS];
#endif

    // Allocate data array and work area arrays.
    ChirpedData = state.data;
    PowerSpectrum = (float*) calloc_a(NumDataPoints, sizeof(float), MEM_ALIGN);
    if (PowerSpectrum == NULL) SETIERROR(MALLOC_FAILED, "PowerSpectrum == NULL");
    if (use_transposed_pot) {
        tPowerSpectrum = (float*) calloc_a(NumDataPoints, sizeof(float), MEM_ALIGN);
        if (tPowerSpectrum == NULL) SETIERROR(MALLOC_FAILED, "tPowerSpectrum == NULL");
    } else {
        tPowerSpectrum=PowerSpectrum;
    }
    AutoCorrelation = (float*)calloc_a(ac_fft_len, sizeof(float), MEM_ALIGN);
    if (AutoCorrelation == NULL) SETIERROR(MALLOC_FAILED, "AutoCorrelation == NULL");

    // boinc_worker_timer();
    FftNum=0;
    FftLen=1;



#ifdef USE_FFTWF
    double sz;
    FILE *wisdom;
    if ((wisdom=boinc_fopen("wisdom.sah","r"))) {
        char *wiz=(char *)calloc_a(1024,64,MEM_ALIGN);
        int n=0;
        while (wiz && n<64*1024 && !feof(wisdom)) {
            n+=fread(wiz+n,1,80,wisdom);
        }
        fftwf_import_wisdom_from_string(wiz);
        free_a(wiz);
        fclose(wisdom);
    }
#endif


#ifdef BOINC_APP_GRAPHICS
    if (sah_graphics) strcpy(sah_graphics->status, "Generating FFT Coefficients");
#endif
    while (bitfield != 0) {
        if (bitfield & 1) {
            swi.analysis_fft_lengths[FftNum]=FftLen;
#ifdef USE_IPP
            int order = 0;
            for (int tmp = FftLen; !(tmp & 1); order++) tmp >>= 1;
            if (ippsFFTInitAlloc_C_32fc(&FftSpec[FftNum], order,
                                        IPP_FFT_NODIV_BY_ANY, ippAlgHintFast)) {
                SETIERROR (MALLOC_FAILED, "ippsFFTInitAlloc failed");
            }
#elif !defined(USE_FFTWF)
            // See docs in fft8g.C for sizing guidelines for BitRevTab and CoeffTab.
            BitRevTab[FftNum] = (int*) calloc_a(3+(int)sqrt((float)swi.analysis_fft_lengths[FftNum]), sizeof(int), MEM_ALIGN);
            if (BitRevTab[FftNum] == NULL)  SETIERROR(MALLOC_FAILED, "BitRevTab[FftNum] == NULL");
            BitRevTab[FftNum][0] = 0;
#else


            WorkData = (sah_complex *)malloc_a(FftLen * sizeof(sah_complex),MEM_ALIGN);
            sah_complex *scratch=(sah_complex *)malloc_a(FftLen*sizeof(sah_complex),MEM_ALIGN);
            if ((WorkData == NULL) || (scratch==NULL)) {
                SETIERROR(MALLOC_FAILED, "WorkData == NULL || scratch == NULL");
            }
            
            // TODO: Deallocate these at the end of the function
            analysis_plans[FftNum] = fftwf_plan_dft_1d(FftLen, scratch, WorkData, FFTW_BACKWARD, FFTW_MEASURE|FFTW_PRESERVE_INPUT);
#endif
            FftNum++;
#ifdef USE_FFTWF
            free_a(scratch);
            free_a(WorkData);
#endif /* USE_FFTWF */

        }
        FftLen*=2;
        bitfield>>=1;
    }
コード例 #6
0
void *calloc_a(size_t size, size_t nitems, size_t alignment) {
  void* p = malloc_a(size*nitems, alignment);
  if (p)
    memset(p, 0, size*nitems);
  return p;
}
コード例 #7
0
// on success, swi.data points to malloced data.
int seti_parse_data(FILE* f, ANALYSIS_STATE& state) {
  unsigned long nbytes, nsamples,samples_per_byte;
  sah_complex *data;
  unsigned long i;
  char *p, buf[256];
  sah_complex *bin_data=0;
  int retval=0;
  FORCE_FRAME_POINTER;

  nsamples = swi.nsamples;
  samples_per_byte=(8/swi.bits_per_sample);
  data = (sah_complex *)malloc_a(nsamples*sizeof(sah_complex), MEM_ALIGN);
  bin_data = (sah_complex *)malloc_a(nsamples*sizeof(sah_complex), MEM_ALIGN);
  if (!data) SETIERROR(MALLOC_FAILED, "!data");
  if (!bin_data) SETIERROR(MALLOC_FAILED, "!bin_data");

  switch(swi.data_type) {
    case DATA_ASCII:
      for (i=0; i<nsamples; i++) {
        p = fgets(buf, 256, f);
        if (!p) {
          SETIERROR(READ_FAILED,"in seti_parse_data");
        }

        sscanf(buf, "%f%f", &data[i][0], &data[i][1]);
      }
      break;
    case DATA_ENCODED:
    case DATA_SUN_BINARY:
      try {
        int nread;
        std::string tmpbuf("");
        fseek(f,0,SEEK_SET);
        nbytes = (nsamples/samples_per_byte);
        tmpbuf.reserve(nbytes*3/2);
        while ((nread=(int)fread(buf,1,sizeof(buf),f))) {
          tmpbuf+=std::string(&(buf[0]),nread);
        }
        std::vector<unsigned char> datav(
           xml_decode_field<unsigned char>(tmpbuf,"data") 
        );
	
        memcpy(bin_data,&(datav[0]),datav.size());
        if (datav.size() < nbytes) throw BAD_DECODE;
      } catch (int i) {
          retval=i;
          if (data) free_a(data);
          if (bin_data) free_a(bin_data);
          SETIERROR(i,"in seti_parse_data()");
      }
      bits_to_floats((unsigned char *)bin_data, data, nsamples);
      memcpy(bin_data,data,nsamples*sizeof(sah_complex));
      state.savedWUData = bin_data;
      break;
/*
#if 0
      nbytes = (nsamples/4);
      bin_data = (unsigned char*)malloc_a((nbytes+2)*sizeof(unsigned char), MEM_ALIGN);
      if (!bin_data) SETIERROR(MALLOC_FAILED, "!bin_data");
      retval = read_bin_data(bin_data, nbytes, f);
      if (retval) {
          if (data) free_a(data);
          if (bin_data) free_a(bin_data);
          SETIERROR(retval,"from read_bin_data()");
      }
      bits_to_floats(bin_data, data, nsamples);
      state.savedWUData = bin_data;
      break;
#endif
*/
  }
  state.npoints = nsamples;
  state.data = data;

#ifdef BOINC_APP_GRAPHICS
  if (sah_graphics) {
      strlcpy(sah_graphics->wu.receiver_name,swi.receiver_cfg.name,255);
      sah_graphics->wu.s4_id = swi.receiver_cfg.s4_id;
      sah_graphics->wu.time_recorded = swi.time_recorded;
      sah_graphics->wu.subband_base = swi.subband_base;
      sah_graphics->wu.start_ra = swi.start_ra;
      sah_graphics->wu.start_dec = swi.start_dec;
      sah_graphics->wu.subband_sample_rate = swi.subband_sample_rate;
      sah_graphics->ready = true;
  }
#endif

  return 0;
}
コード例 #8
0
ファイル: alloc.c プロジェクト: celskeggs/libca
// one crucial difference: returns NULL iff size == 0. On ENOMEM, panics.
void *malloc(ulen size) {
	return malloc_a(&global, size);
}